sql - Best way to add a new column with an initial (but not default) value? -


I have to add a new column in a MS SQL 2005 database with an initial value. However, I do not want to automatically create a default barrier on this column. At the time that I correct the column default / initial value, but it can change over time. Therefore, instead of accepting a default in future access to the table, a value must be specified.

The best I can come up with:

  ALTER TABLE tbl ADD COL INTEGER NULL Update tbl SET col = 1 ALTER TABLE tbl ALTER COLUMN COL INTEGER NOT NULL  

This is slightly ineligible for tables on large scale (100,000 to 1,000,000 records).

I used to add columns with a default and then with the removal of the default barrier. However, I do not know what the default barrier is, and it will not use Cisco and it will put the database in specific knowledge.

Please, should be a better way.

me ALTER TABLE tbl ADD COL INTEGER CONSTRAINT TEMPname DEFAULT 1 First, and <(Probably within the transaction) they are specified after.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -