17

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?

5
  • How about input a space? It will be green?! Commented Jul 6, 2011 at 15:27
  • Yes it will, but I want every new row in the column to just be EMPTY by default. Commented Jul 6, 2011 at 15:32
  • select case when background=red then green end as background from table :P Commented Jul 6, 2011 at 15:32
  • In all seriousness, could you please elaborate on what you see as the difference between null and empty? Do you mean null (as in honest-to-goodness ANSI SQL standard null) vs the empty string? Commented Jul 6, 2011 at 15:34
  • WHERE e.MainContactName IS NULL WHERE e.MainContactName IS NOT NULL IS NOT NULL obviously will bring up all of my rows with text in them... I want it to bring up Every row.. Is that is simple as making the column NOT NULL? Commented Jul 6, 2011 at 15:43

1 Answer 1

27

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Just saying that using DEFAULT is possible with ALTER statement too, and the column will be created with the default value. SQLite ALTER TABLE reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.