程序员人生 网站导航

通过SQL脚本设置主键、自增列、默认值

栏目:Sqlserver时间:2014-02-03 03:17:05
自增列:[PID] [int] IDENTITY (1, 1) NOT NULL
设置主键:这里的PK_t_LockDataNet前缀PK_不好理解,呵呵。
ALTER TABLE hyoa_SysInfo..t_LockDataNet ADD CONSTRAINT
PK_t_LockDataNet PRIMARY KEY CLUSTERED
(
PID
) ON [PRIMARY];
设置默认值:DF_t_LockDataNet_TotalNum前缀DF_表名_字段名
ALTER TABLE hyoa_SysInfo..t_LockDataNet ADD
CONSTRAINT [DF_t_LockDataNet_TotalNum] DEFAULT (5) FOR [TotalNum],
CONSTRAINT [DF_t_LockDataNet_DataTime] DEFAULT (getdate()) FOR [DataTime]
GO

CREATE TABLE hyoa_SysInfo..t_LockDataNet (
[PID] [int] IDENTITY (1, 1) NOT NULL ,
[TotalNum] [int] NULL ,
[ProList] [varchar] (225) COLLATE Chinese_PRC_CI_AS NULL ,
[DataTime] [datetime] NULL ,
[pFlag] [bit] NULL ,
[NodeName] [varchar] (225) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE hyoa_SysInfo..t_LockDataNet ADD CONSTRAINT
PK_t_LockDataNet PRIMARY KEY CLUSTERED
(
PID
) ON [PRIMARY];
ALTER TABLE hyoa_SysInfo..t_LockDataNet ADD
CONSTRAINT [DF_t_LockDataNet_TotalNum] DEFAULT (5) FOR [TotalNum],
CONSTRAINT [DF_t_LockDataNet_DataTime] DEFAULT (getdate()) FOR [DataTime]
GO
------分隔线----------------------------
------分隔线----------------------------

最新技术推荐