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

----选择数据库
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


原文地址:https://www.cnblogs.com/jiangu66/p/3246607.html