Adding a new column to a table in SQL
Jun.30, 2009 in
Computing
Today I found myself needing to add an extra column for a SQL table and I needed to do it using a script. For anyone out there reading this, it’s actually a pretty easy thing to do.
This is what you have to write:
[code lang="sql"]ALTER TABLE tblTable ADD NewCol INT NOT NULL
CONSTRAINT Constraint_NewCol
DEFAULT 0 WITH VALUES[/code]
Obviously you adjust it depending on what kind of column you want to add – the constraint is there to make sure the NOT NULL parameter is adhered to.

Leave a Reply