-->

How to set default value to empty string for TEXT

2019-02-06 14:58发布

问题:

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.