如何将 TEXT 列的默认值设置为空字符串? [英] How to set default value to empty string for TEXT column?

查看:140
本文介绍了如何将 TEXT 列的默认值设置为空字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SQLite 管理器.

I am using SQLite Manager.

我有一个名为MainContactName"的列,它的结构是 TEXT NOT NULL=0

I have a column named "MainContactName" and its structure is TEXT NOT NULL=0

默认情况下,列中的每一行都有一个红色背景",这意味着它是NULL.我怎样才能让它有一个绿色背景"并且是空字符串?

By default, every row in the column has a "red background" meaning it is NULL. How can I make this have a "green background" and be empty string?

推荐答案

您可以在创建表时为列指定默认值.(您似乎无法使用 ALTER 语句添加默认值,因此您必须重新创建表.)

You can specify a default value for the column when you create the table. (It doesn't appear as though you can add a default using an ALTER statement, so you'll have to recreate your table.)

CREATE TABLE your_table_name
(MainContactName TEXT NOT NULL DEFAULT '')

在没有为 MainContactName 指定值的情况下插入的新行的 MainContactName 字段将具有空字符串.您可以尝试在该字段中显式插入空值,但由于 NOT NULL 约束,查询会崩溃.

New rows that are inserted without a value specified for MainContactName will have an empty string for the MainContactName field. You could try to explicitly insert nulls into that field, but the queries would blow up due to the NOT NULL constraint.

这篇关于如何将 TEXT 列的默认值设置为空字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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