SQL Server基础SQL脚本之主外键约束

概要数据库


本系列,几乎都是代码,记得当时写的时候用的是微软的官方实例数据库AdventureWorks_Data.mdf、AdventureWorks_Log.ldf来运行的。app

下载连接:连接: https://pan.baidu.com/s/1pMdLz6N 密码: xvhuide

或者回复“AdventureWorks”来获取连接。spa


代码我就放在文中了。orm

exists(select * from sys.databases where =)
drop database SchDB
create database SchDB on primary
(=,=,=,=,=%),
(=,=,=,=,=),
(=,=,=,=,=),
filegroup XXX
(=,=,=,=,=),
(=,=,=,=,=),
(=,=,=,=,=)
go

alter database SchDB add filegroup YYY
go
alter database SchDb add (
    =,=,
    =,=,=)to filegroup YYY
alter database SchDB modify filegroup YYY use SchDB
create table U3(
    int constraint PK_HAHA primary ,
    age int constraint CK_HAHA check(age (,,)) )
insert into U3 inserted.* values()
insert into U3 inserted.* values()
sp_renameDB ,create schema XIXI
create table XIXI.U(
    int foreign () references U3()
)
create table (
    int  ,
    s_id int
constraint PK_id_s_id primary (,S_id)
)
--建立惟一约束
create table K1(nvarchar() unique)
create table K3(
    int not ,--若是是主键必须添加not nvarchar() constraint UQ_Name2 unique
)
--修改表建立约束
alter table K3 add constraint PK_id primary ()

create table (--主表
aid int primary )
create table (--从表
bid int foreign (bid) references (aid)
)
drop table drop table create table a1(
    aid int constraint PK_a primary ,
    age int check(age between and ),
    sex int check(sex (,)),
    tel nvarchar() check(tel like)

)
create table b2(
    nvarchar()
)

create rule as @like sp_bindrule ,insert into b2 values()
select * from b2
sp_unbindrule drop rule create type HAHA from int not create table (hj    HAHA )
insert into values()

create synonym HIHI AdventureWorks.HumanResources.Department
    select * from HIHI

create partition (int) as range left values(,,)
    create partition (date) as range right values(,
    )

    ---------------------------------
exists(select * from sys.databases where =)
drop database SchDB
create database SchDB on primary
(=,=,=,=,=%),
(=,=,=,=,=),
(=,=,=,=,=),
filegroup XXX
(=,=,=,=,=),
(=,=,=,=,=),
(=,=,=,=,=)
go
alter database HEIHEI add filegroup FG_New
alter database HEIHEI add (=,=)to 
filegroup FG_New
alter partition scheme SC next used FG_New
alter partition () split range()
相关文章
相关标签/搜索