SQL 使用 DEFAULT Empty String 避免 NULL 列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3421659/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 07:07:06  来源:igfitidea点击:

Avoid NULL columns using DEFAULT Empty String

sqlsql-serverdatabasesql-server-2008

提问by GibboK

how can I create a Column with the default value being an empty string?

如何创建一个默认值为空字符串的列?

thanks guys!

谢谢你们!

回答by Lieven Keersmaekers

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

回答by tdammers

Something like:

就像是:

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

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

回答by Reza Roshan

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

在 SQL Server 中,您可以将“列属性 > 默认值或绑定”部分设置为(''). 注意:包括单引号和括号