Altering Tables
As your application development progresses, you might realize that you should have used a different length or data type. Or maybe you shouldn't have allowed NULL in a particular column. The ALTER TABLE command can be used to make these changes. In previous versions of SQL Server, you had to drop most objects and re-create them to make any changes. As I have already said, "Things change!" It's time to figure out how to modify and add new objects or settings to a table, and how to change what is already there. The ALTER TABLE command is used to perform this work. The syntax of the command is
ALTER TABLE table { [ [ALTER COLUMN column_name { new_data_type [ (precision[, scale] ) ] [ NULL | NOT NULL ] | { ADD | DROP} ROWGUIDCOL } ...
Get Sams Teach Yourself Transact-SQL in 21 Days, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.