Add a New Column into table using Procedure

Posted by T.saravanan under Sql Server category on | Points: 40 | Views : 2179
Hi All,

Here i am give a code for add a new column into existing table using procedure.
Table Name: tbl_Test
Existing Columns : Id,Name
New Column : Address

Here @sAddress='Address'

Create proc stp_AddNewColumn
@sAddress varchar(20)
Declare @SqlQuery nVarchar(500) \\ DataType Must be declare as nVarchar (or) ntext (or) nChar
Set @SqlQuery='ALTER TABLE tbl_Test ADD ['+sAddress+'] varchar(50)'
exec sp_executesql @SqlQuery

I hope this code useful to Add a New Column in a Existing Table
Thanks :)

Comments or Responses

Posted by: PandianS on: 8/26/2010 Level:Silver | Status: [Member] [MVP] | Points: 10

Well Try...

Kindly examine the code before you post.

Please change the script and post again...

1. Comment is WRONG
2. Single quots not properly closed
3. Parameter wrongly used as "sAddress" instead of @sAddress

Posted by: T.saravanan on: 8/26/2010 Level:Silver | Status: [Member] [MVP] | Points: 10
Hi PandianS,

Thanks for your response.

Login to post response