通过SQL脚本设置主键、自增列、默认值
来源:程序员人生 发布时间:2014-02-03 03:17:05 阅读次数:2603次
自增列:[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
生活不易,码农辛苦
如果您觉得本网站对您的学习有所帮助,可以手机扫描二维码进行捐赠