SQLite如何将检查约束与另一个表上的Select子查询结合使用 [英] SQLite How to Combine the Check Constraints with Select Subquery on another table

查看:131
本文介绍了SQLite如何将检查约束与另一个表上的Select子查询结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如前所述,我想向表添加约束,并且发现无法同时进行检查"和选择".

As it said, I want to add a constraint to a table, and find cannot make Check and Select together.

这就是我所做的:

Alter Table table2 Add Constraint chk_table2 Check(Colume21 IN (Select Colume11 From Table 1));

为什么会失败?

推荐答案

文档说:

CHECK约束的表达式不能包含子查询.

The expression of a CHECK constraint may not contain a subquery.

无论如何,您以后都不能使用 ALTER TABLE 来添加约束.

In any case, you cannot use ALTER TABLE to add a constraint later.

但是,您的约束看起来像外键,它是 支持.

However, your constraint looks like a foreign key, which is supported.

这篇关于SQLite如何将检查约束与另一个表上的Select子查询结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆