Monday, February 13, 2012

Adding Columns

What is the SQL syntax for adding a column to an already created DB table?ALTER TABLE <your table> ADD <your column> <column definition>

e.g.
ALTER TABLE tbl ADD col VARCHAR(20) NULL|||Originally posted by waspfish
ALTER TABLE <your table> ADD <your column> <column definition>

e.g.
ALTER TABLE tbl ADD col VARCHAR(20) NULL

What is with the "NULL"?

And, another question, how would you edit the name of an existing column?|||Open SQL Server Books Online and search the keywords of "ALTER TABLE" in the tab Index. You can get more information about modifications of a table definition by altering, adding, or dropping columns and constraints, or by disabling or enabling constraints and triggers.|||...or you can do it the lazy, cheating way:

1) Open the table and make the changes you want.
2) Click the "Save changes script" button in the icon bar.
3) Copy the resulting script.
4) Close your table WITHOUT saving changes.

blindman

No comments:

Post a Comment