请问一个约束的问题?
时间:2011-12-01
来源:互联网
作者: chp845 发布时间: 2011-12-01
if object_id('tb','U') is not null drop table tb go create table tb ( id int, age int check(age>0 and age<9) ) go insert into tb select 1,2
作者: pengxuan 发布时间: 2011-12-01
--改一下 if object_id('tb','U') is not null drop table tb go create table tb ( id int, age int check(age>=0 and age<=9) 应该是>=0 and <=9 ) go insert into tb select 1,2
作者: pengxuan 发布时间: 2011-12-01
create table t1 ( col1 char(11) check (col1 like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]') )
作者: gogodiy 发布时间: 2011-12-01
create table tb(id char(11) check (PATINDEX('%[^0-9]%',id) =0) ) go insert into tb values('0102ad') select * From tb drop table tb /* INSERT 语句与 COLUMN CHECK 约束 'CK__tb__id__4A4E069C' 冲突。该冲突发生于数据库 'pubs',表 'tb', column 'id'。 语句已终止。 id ----------- (所影响的行数为 0 行) */
作者: dawugui 发布时间: 2011-12-01
alter table tb add constraint ck_test check(col1 like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]') go
作者: fredrickhu 发布时间: 2011-12-01

抢楼抢得挺快,1、2楼的全是错的
作者: pengxuan 发布时间: 2011-12-01
SQL code
create table t1
(
col1 char(11) check (col1 like '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]')
)
正解
作者: wang7535067 发布时间: 2011-12-01
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28