最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

数据库手动设置数据约束

来源:动视网 责编:小采 时间:2020-11-09 16:21:56
文档

数据库手动设置数据约束

数据库手动设置数据约束:数据库手动设置数据约束 1手动添加[主键约束]PK_Employees_EmpId alter table Employees add constraint PK_Employees_EmpId primary key(EmpId) www.2cto.com 2手动为EmpName增加非空约束 alter table Employees
推荐度:
导读数据库手动设置数据约束:数据库手动设置数据约束 1手动添加[主键约束]PK_Employees_EmpId alter table Employees add constraint PK_Employees_EmpId primary key(EmpId) www.2cto.com 2手动为EmpName增加非空约束 alter table Employees


数据库手动设置数据约束 1手动添加[主键约束]PK_Employees_EmpId alter table Employees add constraint PK_Employees_EmpId primary key(EmpId) www.2cto.com 2手动为EmpName增加非空约束 alter table Employees alter column EmpName varchar(50) not null


数据库手动设置数据约束

1手动添加[主键约束]PK_Employees_EmpId

alter table Employees add constraint PK_Employees_EmpId primary key(EmpId)

www.2cto.com

2手动为EmpName增加非空约束

alter table Employees alter column EmpName varchar(50) not null

3手动为EmpName增加唯一键约束

alter table Employees add constraint UQ_Employees_EmpName unique(EmpName)

go

www.2cto.com

4删除唯一键约束

alter table Employees drop constraint UQ_Employees_EmpName

5为性别增加默认约束,使默认值为"男"

alter table Employees add constraint DF_Employees_EmpGender

default(1) for EmpGender

6为年龄增加检测约束 0-120含0和120

alter table Employees add constraint CK_Employees_EmpAge

check(EmpAge>=0 and EmpAge<=120)

7为性别增加检查约束 非 男 即 女

alter table Employees add constraint CK_Employees_EmpGender

check(EmpGender='男' or EmpGender='女')

8--为员工表增加外键约束

--首先,设置部门表中的DepId为主键,并且外键不能为空

alter table Department add constraint Pk_Deparment_DepId primary key(DepId)

alter table Employee alter column DepId int not null

alter table Employee add constraint FK_Employee_EmpDepId

foreign key(DepId) references Department(DepId) on delete cascade

www.2cto.com

9一条语句删除多个约束

alter table Employees drop constraint FK_Employees_EmpDepId,

CK_Employees_EmpAge,

UQ_Employees_EmpName

10一条语句为表增加多个约束

alter table Employees add constraint

UQ_Employees_EmpName

unique(EmpName),

constraint

CKSSS

check(EmpAge>=0and EmpAge<=120)

文档

数据库手动设置数据约束

数据库手动设置数据约束:数据库手动设置数据约束 1手动添加[主键约束]PK_Employees_EmpId alter table Employees add constraint PK_Employees_EmpId primary key(EmpId) www.2cto.com 2手动为EmpName增加非空约束 alter table Employees
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top