Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Best way to give a default value to a New Column with existing rows

$
0
0

Adding some columns to SQL tables with existing data rows. There are also views created from these tables. The views are used in some report/query software so NULL values are not good. Interested in learning about the best way to set a default value.  These are the ways that I can think of

1) ALTER TABLE using the DEFAULT to add the column and set the default value

++ Adds a constraint which is not terrible. Constraints are just not used much in this shop.

2) ALTER TABLE to add the column then do an UPDATE statement to update the values

++ might be an issue for tables with millions of rows

3) ALTER TABLE to add the column then use ISNULL in the CREATE VIEW


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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