简体   繁体   中英

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

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

If it is string it will empty and if it is int in already created table.

Add DEFAULT constraint

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.

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). About half way down that you can set column defaults.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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