1

在 SQL Server 2012 中,有没有办法让数据库以空字符串 = NULL 的方式运行类似于 Oracle?

我不想在我的数据库中允许空字符串,并希望它们纯粹是 NULLS。

谢谢

4

1 回答 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 <> '')
于 2013-08-14T16:42:23.027 回答