Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

sqlite

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?

like image 226
Greg Avatar asked Jul 06 '11 15:07

Greg


People also ask

How do I set a default column value?

In Object Explorer, right-click the table with columns for which you want to change the scale and select Design. Select the column for which you want to specify a default value. In the Column Properties tab, enter the new default value in the Default Value or Binding property.

Can varchar be empty string?

When you insert an empty string or a NULL value into a varchar column, Oracle treats both the empty string and NULL value as NULL values. Therefore, the software treats the value as a NULL value.

What clause allows you to specify a default value for a column?

Use the DEFAULT clause in the CREATE TABLE statement to specify the default value for the database server to insert into a column when no explicit value for the column is specified. This syntax fragment is part of the Column definition.

What is the default value of string?

The object and string types have a default value of null, representing a null reference that literally is one that does not refer to any object.


1 Answers

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.

like image 185
Rafe Avatar answered Oct 11 '22 11:10

Rafe