135 Views
To add a column with a default value to an existing table in SQL Server, you can use the ALTER TABLE
statement along with the ADD
clause. Here’s the general syntax:
ALTER TABLE table_name
ADD column_name data_type DEFAULT default_value;
For example, suppose you have a table named MyTable
and you want to add a new column named NewColumn
with a default value of 0:
ALTER TABLE MyTable
ADD NewColumn INT DEFAULT 0;
This SQL statement adds a new column named NewColumn
to the MyTable
table with the INT
data type and a default value of 0
.
Remember to replace table_name
, column_name
, data_type
, and default_value
with the appropriate values for your specific scenario.