views:

72

answers:

2

Hi,

how can I create a Column with the default value being an empty string?

thanks guys!

+2  A: 

Something like:

CREATE TABLE foobar (string_column VARCHAR(100) NOT NULL DEFAULT '')

tdammers
+1  A: 

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
What database is this? In Oracle, if you set a VARCHAR to '', it becomes NULL.
Brian Hooper
@Brian Hooper, OP said *using MS SQL 2008*. Nevertheless, good to know Oracle works differently, thanks.
Lieven
Ah. Either some tags have appeared recently or I need new glasses. Sorry, chaps.
Brian Hooper
@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