gpt4 book ai didi

sqlite - 如何在 Sqlite 中向现有表添加唯一约束?

转载 作者:IT王子 更新时间:2023-10-29 06:21:01 24 4
gpt4 key购买 nike

我在 Sqlite 中有一个现有表。如何为其添加唯一约束?

最佳答案

您不能在 SQLite 中向现有表添加约束,(在 SQL 中有这样做的选项)。您需要重新创建具有必要约束的表。

sqlite 中的 alter table 命令只有几个选项可用。请检查图像:

Alter table

同时检查 Sqlite org引用。


编辑

但是你可以为你的表添加唯一索引来达到同样的效果。因此,您可以使用以下查询来实现:

CREATE UNIQUE INDEX your_unique_index ON your_table(column_name);

In most cases, UNIQUE and PRIMARY KEY constraints are implemented bycreating a unique index in the database.

引用:SQLite Constraints

关于sqlite - 如何在 Sqlite 中向现有表添加唯一约束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15497985/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com