1

In SQL Server 2012, is there a way to have the database act similar to Oracle in the way that an empty string = NULL?

I don't want to permit empty strings in my database and want these to purely be NULLS.

Thanks

1 Answer 1

1

SQL Server has no such setting. Instead you could handle this in your data access tier (Entity Framework example) or in a table trigger.

You can use a check constraint to prevent empty strings from being inserted, thus forcing the client to handle the empty-to-null conversion.

ALTER TABLE Table1 WITH CHECK
ADD CONSTRAINT [CK_Table1_Col1] CHECK (Col1 <> '')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that. I've been thinking about it and I don't think it is going to be an issue as I am using SSIS to pull data from Oracle, so I can't see how the values could come back as empty strings anway.

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.