SQLite Modify Column(SQLite 修改列)
问题描述
我需要修改 SQLite 数据库中的一列,但由于数据库已经在生产中,我必须以编程方式进行.根据我的研究,我发现为了做到这一点,我必须执行以下操作.
I need to modify a column in a SQLite database but I have to do it programatically due to the database already being in production. From my research I have found that in order to do this I must do the following.
- 使用新架构创建一个新表
- 将数据从旧表复制到新表
- 放下旧桌子
- 将新表重命名为旧表名
对于应该相对容易的事情来说,这似乎是一项荒谬的工作.没有更简单的方法吗?我需要做的就是更改现有列的约束并为其指定默认值.
That seems like a ridiculous amount of work for something that should be relatively easy. Is there not an easier way? All I need to do is change a constraint on a existing column and give it a default value.
推荐答案
这是 SQLite 众所周知的缺点之一(在 ALTER TABLE 上没有 MODIFY COLUMN 支持),但它位于SQLite 未实现的 SQL 功能列表.
That's one of the better-known drawbacks of SQLite (no MODIFY COLUMN support on ALTER TABLE), but it's on the list of SQL features that SQLite does not implement.
删除了提到它可能在未来版本中受支持的位,因为页面已更新以表明不再是这种情况
edit: Removed bit that mentioned it may being supported in a future release as the page was updated to indicate that is no longer the case
这篇关于SQLite 修改列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQLite 修改列
基础教程推荐
- 在 SQL 中连接多个表 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
