Monday, March 16, 2020

SQL Server... Add column, rename column or update column data types


How to add Add column, rename column, or update column data types in sql server:


Add a new column into the table 

Syntax:

ALTER TABLE Table_Name

ADD column_name datattype;

Note: Newly added column will only be added at the end of the table columns.


Modify a table- drop column name:

Syntax:

ALTER TABLE table_name
DROP COLUMN column_name;



How to rename a column in SQL Server:

EXEC sp_RENAME 'TestTabl1.OldColumnRecordId', '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.

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...