您的位置:首页 > 数据库

[置顶] T-sql sql server 设置主键约束、标示列、唯一约束、默认值、约束、创建表

2013-08-08 20:49 405 查看
----选择数据库
use ythome
go

----查看表是否存在
if Exists
(
select * from sysobjects where name='sys_menu' and type='U'
)
----删除表
begin
drop table sys_menu
end
go

create table sys_menu
(
----Primary  Key 主键约束 IDENTITY(1,1) 标示列初始值1,标示增量1
[id] int not null Primary  Key IDENTITY(1,1),
[type] varchar(16) not null,
----unique ([name]) 唯一约束
[name] nvarchar(50) not null unique ([name]),
----default '#' 默认值
[url] varchar(50) not null default '#',
----check([state] in('N','Y')) 约束
[state] char(1) null check([state] in('N','Y')) default 'Y',
[orderid] int null default 0,
)
go
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: