1、alter table testTB add constraint U_check check(birthday<=getdate())
这句话就约束了出生日期必须小于等于今天,也可以在建表的时候写在最后为 check(birthday<=getdate())
2、创建索引
1 create unique index idx_id_birthday 2 on testTB(ID,birthday)
本文介绍了如何使用SQL语句来添加数据约束条件确保表中数据的有效性,并演示了如何创建唯一索引来提高查询效率。
1、alter table testTB add constraint U_check check(birthday<=getdate())
这句话就约束了出生日期必须小于等于今天,也可以在建表的时候写在最后为 check(birthday<=getdate())
2、创建索引
1 create unique index idx_id_birthday 2 on testTB(ID,birthday)
转载于:https://www.cnblogs.com/yjShow/archive/2012/12/19/2825138.html
45万+

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