Wednesday, July 21, 2021

SQL Server... Add column, rename column or update column data types in sql server

 



Add a new column into the table 


ALTER TABLE Table_Name

ADD column_name datatype;



Modify a table- drop column name:

ALTER TABLE table_name
DROP COLUMN column_name;



How to rename a column in SQL Server:

EXEC sp_RENAME 'TestTabl1.OldColumnName', 'NewColumnName', 'COLUMN'

Query should get successfully get executed. and also if the table is already populated
you would get a warning message like:

Caution: Changing any part of an object name could break scripts and 
stored procedures.

No comments:

Post a Comment

Top 15 SQL interview questions for 2-5 years experienced

  1. What is the difference between UNION and UNION ALL? UNION: To select related information from two tables UNION command is used. It is s...