简体   繁体   English

如何为 SQL Server 中的所有表列设置默认值?

[英]How to set default value for all tables column in SQL Server?

How to set default value for all tables column in SQL Server?如何为 SQL Server 中的所有表列设置默认值?

If it is string it will empty and if it is int in already created table.如果它是字符串,它将为空,如果它在已经创建的表中是 int。

Add DEFAULT constraint添加DEFAULT约束

Here is the way to do it:这是这样做的方法:

CREATE TABLE Persons
(
id int NOT NULL,
LName varchar(25) NOT NULL,
FName varchar(25),
Addr varchar(255),
City varchar(255) DEFAULT 'Hawaii'
)

You can also do this in SQL server management studio, if you have designed you table using the GUI as opposed to creating it with a SQL statement.如果您使用 GUI 设计表格而不是使用 SQL 语句创建表格,那么您也可以在 SQL 服务器管理工​​作室中执行此操作。

To do this (off the top of my head), select the column you are editing, the properties window should be visible (if not i think f4 will open it).为此(在我的脑海中),选择您正在编辑的列,属性窗口应该是可见的(如果不是,我认为 f4 会打开它)。 About half way down that you can set column defaults.大约一半,您可以设置列默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM