创建后,我可以将 sqlite 表中的列更改为 AUTOINCREMENT 吗? [英] Can I alter a column in an sqlite table to AUTOINCREMENT after creation?

查看:30
本文介绍了创建后,我可以将 sqlite 表中的列更改为 AUTOINCREMENT 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在制作表格后制作字段AUTOINCREMENT吗?例如,如果您创建一个这样的表:

Can I make a field AUTOINCREMENT after made a table? For example, if you create a table like this:

create table person(id integer primary key, name text);

后来意识到它需要自动递增.我如何修复它,即在 MySQL 中你可以这样做:

Then later on realise it needs to auto increment. How do I fix it, ie in MySQL you can do:

alter table person modify column id integer auto_increment

表创建是创建列AUTOINCREMENT的唯一机会吗?

Is table creation the only opportunity to make a column AUTOINCREMENT?

推荐答案

您可以将内容转储到新表:

You can dump the content to a new table:

CREATE TABLE failed_banks_id (id integer primary key autoincrement, name text, city text, state text, zip integer, acquired_by text, close_date date, updated_date date);

INSERT INTO failed_banks_id(name, city, state, zip, acquired_by,close_date, updated_date)
SELECT name, city, state, zip, acquired_by,close_date, updated_date
FROM failed_banks;

并重命名表:

DROP TABLE failed_banks;
ALTER TABLE failed_banks_id RENAME TO failed_banks;

这篇关于创建后,我可以将 sqlite 表中的列更改为 AUTOINCREMENT 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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