如何在sqlite中更改记录的主键? [英] How to change primary key of a record in sqlite?
本文介绍了如何在sqlite中更改记录的主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有TEXT主键的表
I have table that has a TEXT primary key
CREATE TABLE tbl1{
a1 TEXT PRIMARY KEY,
...
);
( a1
列是外键
如何更改 a1
的值?
如果我愿意
更新tbl1 SET a1 =吗?在哪里a1 =?
UPDATE tbl1 SET a1 = ? WHERE a1 = ?
我遇到约束违规错误
推荐答案
您永远不要更改主键;最好使用 INTEGER主键,并以实际URL为普通数据列。
You should never change primary keys; it would be a better idea to use an INTEGER PRIMARY KEY and have the actual URL be a normal data column.
如果您确实要更改作为外键目标的键,则应将外键约束声明为推迟,这样您就可以在同一笔交易中调整外键值。
If you really want change a key that is the target of a foreign key, you should declare the foreign key constraint as deferred so that you are able to adjust the foreign key value in the same transaction.
这篇关于如何在sqlite中更改记录的主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文