0.创建表
create table Users ( Id int, Name nvarchar(32), Phone nvarchar(16), Email nvarchar(128), Role_Id uniqueidentifier ) go create table Roles ( Id uniqueidentifier primary key, Name nvarchar(32) not null )
1.增加主键
alter table Users add constraint PK_Users_Id primary key(Id)
2.增加唯一约束
alter table Users add constraint UQ_Users_Name unique(Name)
3.增加检查约束
alter table Users add constraint CK_Users_Age check(Age>0 and Age<100)
4.增加非空约束
alter table Users add constraint NN_Users_Phone check(Phone is not null)
5.增加默认约束
alter table Users add constraint DF_Users_Email default('123456@qq.com') for Email
6.增加外键
alter table Users add constraint FK_Users_Roles_Id foreign key (Role_Id) references Roles(Id)
7.删除主外键或约束
alter table Users drop constraint FK_Users_Roles_Id