设为首页 加入收藏

TOP

SQL Server约束简析(二)
2014-11-23 22:26:55 来源: 作者: 【 】 浏览:18
Tags:SQL Server 约束 简析
ar(32) not null foreign key references myTB(id),
name nvarchar(32)
)
在Sql Server、Orcale、MS Access、My Sql 都支持的添加Foreign Key语法:
Create table myTB1
(
id nvarchar(32) not null primary key,
name nvarchar(32),
Constraint foreignName foreign key(id) references myTB(id)
)
在Sql Server、Orcale、MS Access、My Sql 的表已存在情况下,向表添加外键约束的语法:
Alter table myTB1
Add foreign key(id) references myTB(id) --这样写 系统会自定义约束名称
Alter table myTB1
Add Constraint foreignName foreign key(id) references myTB(id) --这样写自己可以自定义约束名称
在Sql Server、Orcale、MS Access 中删除外键约束的语法:
Alter table myTB1
Drop Constraint foreignName;
在My Sql 中删除外键约束的语法:
Alter table myTB1
Drop foreign key foreignName;
5、Check :用于控制字段的值范围。
在Sql Server、My Sql 支持的添加check 语法:
Create table myCheck
(
id nvarchar(32) not null,
age int not null,
check (age>15 and age <30) www.2cto.com
)
在Sql Server、Orcale、MS Access 支持的添加 check 语法:
Create table myCheck
(
id nvarchar(32) not null,
age int not null check (age>15 and age<30)
)
在Sql Server、Orcale、MS Access、My Sql 都支持的添加 check 语法:
Create table myCheck
(
id nvarchar(32) not null,
age int not null,
constraint checkName check (age<15 and age>30)
)
在Sql Server、Orcale、MS Access、My Sql 的表已存在情况下,向表添加check约束的语法:
Alter table myCheck
add check (id='celly'); --这样定义是系统自定义 check约束名称。
Alter table myCheck
add constraint checkName check(id='celly'); --这样定义是自己自定义 check约束名称。
在 Sql Server、Orcale、MS Access 删除表已存在的 check 约束的语法:
Alter table myCheck
drop constraint checkName
6、Default :用于设置新记录的默认值。
在Sql Server、Orcale、MS Access、My Sql 添加default约束的语法:
Create table myDefault
( www.2cto.com
id int,
name nvarchar(32) default 'celly'
)
在My Sql 的已存在表中添加 字段默认值:
Alter table myDefault
Alter [id] set default 0
在 Sql Server、Orcale、MS Access 的已存在表中添加 字段默认值:
Alter table myDefault
Alter column [id] set default 0
在 My Sql 中删除字段默认值语法:
Alter table myDefault
Alter ColumnName drop default
来自痕网工作室
首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇卸载SQL Pretty Printer插件时的.. 下一篇CentOS 5.4 安装和卸载桌面

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: