--创建表的同时创建约束

use tempdb

if Object_ID('testDB') is not Null

drop table testDB;

CREATE TABLE testDB(

ID INT IDENTITY(1,1) NOT NULL,

[Name] NVARCHAR(50) NOT NULL ,

Description NVARCHAR(2000) NOT NULL,

CreateDate Datetime Default(getDate()),

CONSTRAINT PK_ID PRIMARY KEY CLUSTERED (ID ASC),

CONSTRAINT CHK_ID Check (ID between 1 and 1000)

)

--删除约束

use tempdb

alter Table testDB Drop Constraint PK_ID

--修改约束

use tempdb

alter Table testDB Add Constraint PK_ID Primary key CLUSTERED(ID ASC)

1:约束格式

CONSTRAINT Constraint_name Constraint_type(col)

Constraint_type:check,Primary key,Foreign key,unique

相关文章:

  • 2021-05-17
  • 2022-02-15
  • 2022-12-23
  • 2021-05-28
  • 2021-06-11
  • 2022-01-05
  • 2021-07-07
  • 2021-09-18
猜你喜欢
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2021-11-06
相关资源
相似解决方案