SQLite table constraint - unique on multiple columns(SQLite 表约束 - 在多列上唯一)
问题描述
我可以在 SQLite 网站上找到语法图表",但没有示例,我的代码崩溃了.我有其他表在单个列上具有唯一约束,但我想在两列上向表添加约束.这就是我所拥有的导致 SQLiteException 消息语法错误"的原因.
I can find syntax "charts" on this on the SQLite website, but no examples and my code is crashing. I have other tables with unique constraints on a single column, but I want to add a constraint to the table on two columns. This is what I have that is causing an SQLiteException with the message "syntax error".
CREATE TABLE name (column defs)
UNIQUE (col_name1, col_name2) ON CONFLICT REPLACE
我这样做是基于以下几点:
I'm doing this based on the following:
表格约束
要清楚,我提供的链接上的文档说CONTSTRAINT name 应该在我的约束定义之前.
To be clear, the documentation on the link I provided says that CONTSTRAINT name should come before my constraint definition.
不过,可能会导致解决方案的一些事情是,在我括号中的列定义之后的任何内容都是调试器所抱怨的.
Something that may lead to the solution though is that whatever follows my parenthesized column definitions is what the debugger complains about.
如果我把
...last_column_name last_col_datatype) CONSTRAINT ...
错误在靠近CONSTRAINT":语法错误
如果我把
...last_column_name last_col_datatype) UNIQUE ...
错误在UNIQUE"附近:语法错误
推荐答案
将 UNIQUE 声明放在列定义部分;工作示例:
Put the UNIQUE declaration within the column definition section; working example:
CREATE TABLE a (
i INT,
j INT,
UNIQUE(i, j) ON CONFLICT REPLACE
);
这篇关于SQLite 表约束 - 在多列上唯一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQLite 表约束 - 在多列上唯一
基础教程推荐
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 无法解决整理冲突 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 在 SQL 中连接多个表 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
