软件下载 | 资讯教程 | 最近更新 | 下载排行 | 一键转帖 | 发布投稿
您的位置:最火下载站 > 网络编程 > SQL SERVER > 通过SQL脚本设置主键、自增列、默认值

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

自增列:[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
    相关阅读
    网友评论
    栏目导航
    推荐软件