约束 constraint 简单整理
约束 Constraint
Primary Key
Foreigh Key
Unique
Check
Default
=================
Create:
Use DB_Name
go
Alter Table Table_name
// Primary Key
Add constraint IX_IndexName Primary Key (Column_Name1[Column_Name_2 / Column_Name_3 ])
---------------
//Foreign Key
Add constraint RelationName_FK Foreign Key (Column_Name1[Column_Name_2 / Column_Name_3 ])
REFERENCES Table_Name_2 (Column_Name1[Column_Name_2 / Column_Name_3 ])
-----------------
// Unique 在定义Index时作选项创建
//Check
Add Constraint CK_CheckName Check (XXXNo like '[0-9][0-9][0-9]')
add Constraint CK_CheckName2 Check (ID>=1)
------------------
//Default
Add Constraint DF_DefaultNAme Default ('LALA') for Column_Name
--------------------
go
go
Alter Table Table_name
// Primary Key
Add constraint IX_IndexName Primary Key (Column_Name1[Column_Name_2 / Column_Name_3 ])
---------------
//Foreign Key
Add constraint RelationName_FK Foreign Key (Column_Name1[Column_Name_2 / Column_Name_3 ])
REFERENCES Table_Name_2 (Column_Name1[Column_Name_2 / Column_Name_3 ])
-----------------
// Unique 在定义Index时作选项创建
//Check
Add Constraint CK_CheckName Check (XXXNo like '[0-9][0-9][0-9]')
add Constraint CK_CheckName2 Check (ID>=1)
------------------
//Default
Add Constraint DF_DefaultNAme Default ('LALA') for Column_Name
--------------------
go
---
Drop
Use DB_name
go
Alter Table Table_Name
Drop Constraint Relation_Name
go
go
Alter Table Table_Name
Drop Constraint Relation_Name
go
当然 在控制面板设置会更加方便 只是这样也相对随心所欲。方法多总能给自己留点后路
posted on 2006-01-08 06:30 Royman.Chen 阅读(643) 评论(1) 编辑 收藏 举报