加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

检查SQLite中是否存在列

发布时间:2020-12-12 19:14:05 所属栏目:百科 来源:网络整理
导读:我需要检查一下列是否存在,如果它不存在添加它。从我的研究看来,sqlite不支持IF语句,而是应该使用case语句。 这是我到目前为止 SELECT CASE WHEN exists(select * from qaqc.columns where Name = "arg" and Object_ID = Object_ID("QAQC_Tasks")) = 0 TH
我需要检查一下列是否存在,如果它不存在添加它。从我的研究看来,sqlite不支持IF语句,而是应该使用case语句。

这是我到目前为止

SELECT CASE WHEN exists(select * from qaqc.columns where Name = "arg" and Object_ID = Object_ID("QAQC_Tasks")) = 0 THEN ALTER TABLE QAQC_Tasks ADD arg INT DEFAULT(0);

但是我收到错误:“ALTER”附近:语法错误。

有任何想法吗?

您不能使用ALTER TABLE withcase。

您正在寻找获取表的列名:: ::

PRAGMA table_info(table-name);

在PRAGMA上查看本教程

This pragma returns one row for each column in the named table. Columns in the result set include the column name,data type,whether or not the column can be NULL,and the default value for the column. The “pk” column in the result set is zero for columns that are not part of the primary key,and is the index of the column in the primary key for columns that are part of the primary key.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读