创建表中的 CHECK 中的通配符作为字符串
我创建了一个存储员工记录的信息表,其 SQL 查询如下...
CREATE TABLE info1 (
empid VARCHAR(8) PRIMARY KEY CONSTRAINT empchk
CHECK (empid IN ('kh\%' ESCAPE '\''),
initials CHAR(6), fname CHAR(25) NOT NULL,
lname CHAR(25),
userstatus INTEGER NOT NULL,
designation CHAR(10) NOT NULL
);
现在,正如您所见 empid
中的约束是 kh%
其中 - 到目前为止我记得 - %
意味着任意数量的以下字符(当然限于 8
)可以是任何东西,对吗?
我正在使用 Java DB,奇怪的是它也将 %
符号作为字符串的一部分,因此如果我输入 khce0001
,它会显示 empchk
> 违规,只需要 kh%
我该怎么办? 为什么会发生这种情况?
I created an info table that stores employee record, the SQL query for it as follows...
CREATE TABLE info1 (
empid VARCHAR(8) PRIMARY KEY CONSTRAINT empchk
CHECK (empid IN ('kh\%' ESCAPE '\''),
initials CHAR(6), fname CHAR(25) NOT NULL,
lname CHAR(25),
userstatus INTEGER NOT NULL,
designation CHAR(10) NOT NULL
);
Now, as you can see constraint in empid
is kh%
where - as far as I remember - %
means that any number of the following characters (limited to 8
of course) can be anything, right?
I am using Java DB and strangely it has taken the %
symbol also to be a part of the string so if I enter khce0001
, it says empchk
violation, it only takes in kh%
What should I do? Why is this happening?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个 SQL 查询中的错误是我使用了
IN
而不是LIKE
(我相信它会进行通配符检查),所以我用...删除了约束
并用...更改了表格
因此正确的 SQL 查询应该是...
The mistake in this SQL query is that I have used
IN
instead ofLIKE
(which I believe does wildcard checking), soI dropped the constraint with...
and altered the table with...
and hence the correct SQL Query should have been...