Thursday, June 18, 2015

How to do modifications to columns in SQL

First let us create Employee table in our database.

CREATE TABLE [dbo].[Employee]([EmpID] [int] NOT NULL,[FirstName] [nvarchar](250) NOT NULL,[LastName] [nvarchar](250) NULL,[Salary] [money] NULL,[DeptID] [int] NULL)

Modification to existing column in table:

ALTER TABLE [dbo].[Employee]ALTER COLUMN [DeptID] INT NOT NULL


Adding new column into the table:

ALTER TABLE [dbo].[Employee]ADD Phone INT NULL


Removing the column from a table:

ALTER TABLE [dbo].[Employee]DROP COLUMN Phone


Removing the table from database:

DROP TABLE [dbo].[Employee]



Labels: , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home