How to set default value to empty string for TEXT column?

久未见 提交于 2020-01-21 01:35:30

问题


I am using SQLite Manager.

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

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?


回答1:


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 '')

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.



来源:https://stackoverflow.com/questions/6598881/how-to-set-default-value-to-empty-string-for-text-column

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!