请哪位帮我写写这个检查约束。谢了。 请哪位帮我写写这个检查约束。谢了。我自己试着写了很久都不是很好。。类型,char(6)可以为null可以为 6个空格可以为[0-1][0-9][0-9][:][0-5][0-9]谢了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 create table tb(col char(6))goalter table tb add constraint chk_tb check(col=' ' or col like '[0-1][0-9][0-9][:][0-5][0-9]')go if object_id('[tb]') is not null drop table [tb] go create table [tb]([col] char(6),check(col like '[0-1][0-9][0-9][:][0-5][0-9]' or col is null or col like '[ ][ ][ ][ ][ ][ ]'))/*可以为null 可以为 6个空格 可以为[0-1][0-9][0-9][:][0-5][0-9] */insert tb select '123456'/*消息 547,级别 16,状态 0,第 1 行INSERT 语句与 CHECK 约束"CK__tb__col__110B679F"冲突。该冲突发生于数据库"test1",表"dbo.tb", column 'col'。语句已终止。*/insert tb select ' '/*(1 行受影响)*/insert tb select NULL/*(1 行受影响)*/ ALTER table LI add constraint c_LI CHECK(COL1 LIKE '[0-1][0-9][0-9][:][0-5][0-9]') 比对结果 聚合运算中出现除零错误,如何处理 对于Microsoft SQL怎样设置备份呢 如何附加数据库模板? 如何是插入的数据不被触发器更改? 着急用,求大神们帮忙写个sql或者给个思路吧 SQL Server中如何存入jpg图片? 查找表内字段更新 求助 在pb中建一个asa数据库? 一个简单的设计问题 多条件A表减B表
go
alter table tb
add constraint chk_tb check(col=' ' or col like '[0-1][0-9][0-9][:][0-5][0-9]')
go
go
create table [tb]([col] char(6),check(col like '[0-1][0-9][0-9][:][0-5][0-9]' or col is null or col like '[ ][ ][ ][ ][ ][ ]'))/*
可以为null
可以为 6个空格
可以为[0-1][0-9][0-9][:][0-5][0-9] */insert tb select '123456'
/*
消息 547,级别 16,状态 0,第 1 行
INSERT 语句与 CHECK 约束"CK__tb__col__110B679F"冲突。该冲突发生于数据库"test1",表"dbo.tb", column 'col'。
语句已终止。
*/
insert tb select ' '
/*
(1 行受影响)
*/
insert tb select NULL
/*
(1 行受影响)
*/