发布网友 发布时间:2022-04-11 11:29
共2个回答
懂视网 时间:2022-04-11 15:50
TABLE [dbo].[BASE_UserInDept]( [HospitalID] [int] NOT NULL, [UserID] [int] NOT NULL, [DeptCode] [varchar](10) NOT NULL, [RoleID] [int] NOT NULL ) ON [PRIMARY] GO2、可以在建表的时候添加主键
CREATE TABLE [dbo].[BASE_UserInDept]( [HospitalID] [int] NOT NULL, [UserID] [int] NOT NULL, [DeptCode] [varchar](10) NOT NULL, [RoleID] [int] NOT NULL,
--添加主键约束 CONSTRAINT [PK_BASE_UserInDept] PRIMARY KEY CLUSTERED ( [HospitalID] ASC, [UserID] ASC, [DeptCode] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO
--添加主键DF_BASE_UserInDept默认约束
ALTER TABLE [dbo].[BASE_UserInDept] ADD CONSTRAINT [DF_BASE_UserInDept] DEFAULT ((0)) FOR [RoleID] GO
3、也可以直接使用
ALTER TABLE table ADD CONSTRAINT 键名 PRIMARY KEY ...添加
ALTER TABLE [dbo].[BASE_UserInDept] ADD CONSTRAINT [PK_BASE_UserInDept] PRIMARY KEY CLUSTERED ( [HospitalID] ASC, [UserID] ASC, [DeptCode] ASC )ON [PRIMARY]
4、清空表数据语法
TRUNCATE TABLE name
mssql清空数据和添加主键约束语法
标签:spi clu code class tab col create trunc sql
热心网友 时间:2022-04-11 12:58
asp删除表主键