首页 > 开发 > 综合 > 正文

数据库系列学习(十)-约束

2024-07-21 02:46:04
字体:
来源:转载
供稿:网友
数据库系列学习(十)-约束
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))

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表