1.主鍵約束(PRimary key)
create table T_User1( Id int primary key identity(1,1), UName nvarchar(10))
2.非空約束(not null)create table T_User2( Id int primary key identity(1,1), UName nvarchar(10) not null)3.1唯一約束(unique)-單列create table T_User3( Id int primary key identity(1,1), UNo nvarchar(10)unique)3.2唯一約束-多列create table T_User4( Id int primary key identity(1,1), UAddress nvarchar(10), UName nvarchar(10), constraint uniq_addr_name unique(UAddress,UName))4.1Check約束(check)-單列create table T_User5( Id int primary key identity(1,1), UName nvarchar(10)check(len(UName)<4), UAge int check(UAge>0))4.2Check約束-多列create table T_User6( Id int primary key identity(1,1), UWorkYear int, UAge int, constraint ck_wkyear_age check(UWorkYear<UAge))5.外鍵約束(foreign key)create table T_Author( AId int primary key identity(1,1), AName nvarchar(10))create table T_Blog( BId int primary key identity(1,1), BAuthorId int, foreign key(BAuthorId) references T_Author(AId))
新聞熱點
疑難解答