An Engineers Notebook

SQL: Add, Alter and rename columns

This SQL code will Alter the Employee’s table in the TechShizz database and ADD two columns called ActiveFlag and Modified date and also Alter an existing column by changinge it’s data type.

NOTICE for the syntax to work here, a semi-colon must be used at the end of the ADD statment.

Finally, the EXEC command is used to rename a column.


USE TechShizz
GO

ALTER TABLE Employees
    ADD
        ActiveFlag bit NOT NULL,
        ModifiedDate datetime NOT NULL;
ALTER TABLE Products
    ALTER COLUMN Price money

EXEC sp_rename ‘Sales’,‘SaleOrders’

Leave a Reply

Your email address will not be published.