Powered by Blogger.

Saturday, February 15, 2014

Add new column to existing table in sql server 2008




In this post we will discuss how to add a new column to an existing table in sql server 2008.

You can also check my previous posts on Solution for error Saving changes is not permitted sql 2008 [Solution here], WCF tutorial and example in C#.Net and Left outer join and Right outer join in SQL Server [Read here].

You can add columns easily to an existing table in the database.

Below is a query which will add a DateTime type column which will not accept NULL value and put default value as the current datetime.

Use TestDB
ALTER TABLE Employees
ADD ModifiedDate DateTime NOT NULL DEFAULT(Getdate())
GO

Below is the query that will add a varchar type column to the table which can take NULL values.

Use TestDB
ALTER TABLE Employees
ADD Location varchar(200)null
GO

Check the figure to know about the table structure.




0 comments

Post a Comment