How can I create a column with the default value being an empty string?
Asked
Active
Viewed 4.6k times
3 Answers
27
You can read up on the subject here
CREATE TABLE dbo.Test (ID INTEGER, EmptyString VARCHAR(32) DEFAULT '')
INSERT INTO dbo.Test (ID) VALUES (1)
INSERT INTO dbo.Test (ID) VALUES (2)
SELECT * FROM dbo.Test
DROP TABLE dbo.Test

Lieven Keersmaekers
- 57,207
- 13
- 112
- 146
-
What database is this? In Oracle, if you set a VARCHAR to '', it becomes NULL. – Brian Hooper Aug 06 '10 at 09:59
-
1@Brian Hooper, OP said *using MS SQL 2008*. Nevertheless, good to know Oracle works differently, thanks. – Lieven Keersmaekers Aug 06 '10 at 11:34
-
1Ah. Either some tags have appeared recently or I need new glasses. Sorry, chaps. – Brian Hooper Aug 06 '10 at 11:58
-
1@Brian, don't worry, your eyes are fine. I changed the tags after your comment and removed the *using MS SQL 2008* from the question. – Lieven Keersmaekers Aug 06 '10 at 14:05
9
In SQL server you can set "Column properties > Default value or binding" section to ('')
. NOTE: It includes single quotation and parenthesis

dashtinejad
- 6,193
- 4
- 28
- 44

Reza Roshan
- 147
- 3
- 7
9
Something like:
CREATE TABLE foobar (string_column VARCHAR(100) NOT NULL DEFAULT '')

tdammers
- 20,353
- 1
- 39
- 56