三、数据完整性

来源:互联网 发布:mt4自动交易软件 编辑:程序博客网 时间:2024/06/05 11:06
NOT NUL L不为空
Unique 唯一
Primary Key 主键
Foreign Key 外键
Check 限制 
默认值


--創建约束create table Persons(id int identity primary key,--主uid varchar(50) not null unique,--唯一name nvarchar(20) not null,--不为空sex int not null check (sex=1 or sex=2),    --限制new_date datetime default getdate()--默认)create table Persons2(id int,name nvarchar(20)foreign key (id) references persons(id) --外键)--新增約束ALTER TABLE Persons ADD UNIQUE (uid)ALTER TABLE Persons ADD PRIMARY KEY (Id_P)ALTER TABLE Persons ADD CHECK (Id_P>0)ALTER TABLE Persons ALTER COLUMN new_date SET DEFAULT getdate()--刪除約束ALTER TABLE Persons DROP CONSTRAINT uc_PersonIDALTER TABLE Persons DROP CONSTRAINT PK__persons__3213E83F78B4BB21ALTER TABLE Persons DROP CONSTRAINT chk_PersonALTER TABLE Persons ALTER COLUMN City DROP DEFAULT


原创粉丝点击