20

How can I create a column with the default value being an empty string?

3 Answers 3

28

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
Sign up to request clarification or add additional context in comments.

4 Comments

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

In SQL server you can set "Column properties > Default value or binding" section to (''). NOTE: It includes single quotation and parenthesis

Comments

9

Something like:

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

Comments

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.