Quantcast
Channel: How to add a column with a default value to an existing table in SQL Server? - Stack Overflow
Browsing all 91 articles
Browse latest View live

Answer by giá vàng for How to add a column with a default value to an...

Use:ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}Reference: ALTER TABLE (Transact-SQL) (MSDN)

View Article


Answer by Jack for How to add a column with a default value to an existing...

In SQL Server 2008-R2, I go to the design mode - in a test database - and add my two columns using the designer and made the settings with the GUI, and then the infamous Right-Click gives the option...

View Article


Answer by gngolakia for How to add a column with a default value to an...

You can do the thing with T-SQL in the following way. ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}As well as you can use SQL...

View Article

Answer by phunk_munkie for How to add a column with a default value to an...

When adding a nullable column, WITH VALUES will ensure that the specific DEFAULT value is applied to existing rows:ALTER TABLE table_nameADD column_name BIT -- Demonstration with NULL-able column...

View Article

Answer by JerryOL for How to add a column with a default value to an existing...

Use:-- Add a column with a default DateTime -- to capture when each record is added.ALTER TABLE myTableName ADD RecordAddedDate SMALLDATETIME NULL DEFAULT (GETDATE()) GO

View Article


Answer by jalbert for How to add a column with a default value to an existing...

Beware when the column you are adding has a NOT NULL constraint, yet does not have a DEFAULT constraint (value). The ALTER TABLE statement will fail in that case if the table has any rows in it. The...

View Article

Answer by ddc0660 for How to add a column with a default value to an existing...

ALTER TABLE <table name> ADD <new column name> <data type> NOT NULLGOALTER TABLE <table name> ADD CONSTRAINT <constraint name> DEFAULT <default value> FOR <new...

View Article

Answer by James Boother for How to add a column with a default value to an...

Syntax:ALTER TABLE {TABLENAME} ADD {COLUMNNAME} {TYPE} {NULL|NOT NULL} CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}WITH VALUESExample:ALTER TABLE SomeTable ADD SomeCol Bit NULL --Or NOT NULL....

View Article


Answer by dbugger for How to add a column with a default value to an existing...

ALTER TABLE ProtocolsADD ProtocolTypeID int NOT NULL DEFAULT(1)GOThe inclusion of the DEFAULT fills the column in existing rows with the default value, so the NOT NULL constraint is not violated.

View Article


Answer by Benjamin Autin for How to add a column with a default value to an...

ALTER TABLE ADD ColumnName {Column_Type} ConstraintThe MSDN article ALTER TABLE (Transact-SQL) has all of the alter table syntax.

View Article

How to add a column with a default value to an existing table in SQL Server?

How can I add a column with a default value to an existing table in SQL Server 2000 / SQL Server 2005?

View Article
Browsing all 91 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>