ALTER syntax

The ALTER TABLE statement is used to add, delete and modify columns in an existing table.

Add column
ALTER TABLE table_name ADD new_col_name datatype

Delete column
ALTER TABLE table_name DROP COLUMN col_name

Modify datatype of a column
ALTER TABLE table_name ALTER COLUMN col_name datatype
We cannot rename a column with ALTER TABLE statement. For renaming a column or a table use SP_RENAME statement.

Rename a Database
ALTER DATABASE old_database_name MODIFY Name = new_database_name ;

Alter database properties
ALTER DATABASE [db_name] MODIFY FILE ( NAME = N'db_name' , SIZE = 512MB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) GO ALTER DATABASE [db_name] MODIFY FILE ( NAME = N'db_name_log' , SIZE = 256MB , MAXSIZE = UNLIMITED , FILEGROWTH = 10%) GO

No comments:

Post a Comment