The ALTER TABLE Statement
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.To add a column in a table, use the following syntax:
=======================
ALTER TABLE table_name
ADD column_name datatype
ADD column_name datatype
============================
To delete a column in a table, use the following syntax
===============================
===============================
ALTER TABLE table_name
DROP COLUMN column_name
DROP COLUMN column_name
=========================
To change the data type of a column in a table, use the following syntax:
=======================
=========================
=======================
ALTER TABLE table_name
ALTER COLUMN column_name datatype
ALTER COLUMN column_name datatype
To rename column name there is no way with alter command
we use sp_rename proc for this.
=========================================
The script for renaming any column :
sp_RENAME 'TableName.[OldColumnName]' , '[NewColumnName]', 'COLUMN'
-----------------------------------------------
The script for renaming any object (table, sp etc) :
sp_RENAME '[OldTableName]' , '[NewTableName]'
======================================
No comments:
Post a Comment