T-sql sql server 設定主鍵約束、標示列、唯一約束、預設值、約束、建立表
阿新 • • 發佈:2019-02-05
----選擇資料庫 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