Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant add column with out dropping table in sql server [duplicate]

I have a production table that has 100 million rows , and for a reporting purpose we need to add one additional column which will be a Numeric (18,0).Obviously SQL won't let me add that column with out dropping the table.Any other way that i can do this with out affecting the data?

like image 536
SQLHunter Avatar asked Oct 18 '25 16:10

SQLHunter


1 Answers

You can add a column without dropping the table.

ALTER TABLE YourTable
ADD  SomeColumnName NUMERIC(18,0)

UPDATE

If you want the column NOT NULL then you'll have to make it accept NULL first, then set the values through an update, and lastly alter the column to NOT NULL.

Or set a default value such as

ALTER TABLE YourTable
ADD SomeColumnName DECIMAL(18,0) NOT NULL DEFAULT 1
like image 139
SQLChao Avatar answered Oct 21 '25 06:10

SQLChao



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!