开发者

SQL Server Nullable Column

开发者 https://www.devze.com 2023-03-02 23:05 出处:网络
I have a SQL Server table with a few columns of type varchar which are nullable. When an aspx page posts data if thetextbox is empty, the database table column is updated to an empty string.

I have a SQL Server table with a few columns of type varchar which are nullable. When an aspx page posts data if the textbox is empty, the database table column is updated to an empty string.

To maintain the null value rather han have it replaced by an empty string, I can either have the logic to change the empty string to System.DBnull in the middle tier c# code or do so in the stored procedure.

Are there other better ways 开发者_StackOverflow中文版to handle this situation?


you can use a trigger or do it in the proc, you can use the NULLIF function

Example

DECLARE @d VARCHAR(20)
SELECT @d = ''
SELECT NULLIF(@d,'')


I would probably put it near the code that makes a decision based on the distinction between an empty string and a null string. If there is no difference between their meaning or the resulting behavior of the application, I would suggest making the field non-nullable and sticking with an empty string.

0

精彩评论

暂无评论...
验证码 换一张
取 消