Reputation: 5522
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
Upvotes: 1
Views: 173
Reputation: 21244
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 <> '')
Upvotes: 1