建立表时,对字段加唯一和非空条件
//not null,放在default前会出错
create table tbEmp(
eid int primary key,
ename varchar2(20) unique not null
constraints Ck_name check (length(ename) between 1 and 6 ),
esex varchar2(3) default'男' not null,
eAge int not null ,
constraints Ck_age check(eAge between 18 and 50),
eaddr varchar2(100) default'地址不详'
)
这篇博客介绍了如何在SQL中创建一个包含唯一和非空约束的表。示例展示了如何为`ename`字段设置唯一且非空的约束,以及如何为`esex`和`eAge`字段添加默认值和非空约束,并通过检查约束确保数据的有效性。

被折叠的 条评论
为什么被折叠?



