Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding columns to an existing table

Status
Not open for further replies.

Proqrammer

Programmer
Sep 17, 2006
64
Hi there I wanna add a new column to an existing table, I'm using vb.net 2005.

I found sp_repladdcolumn but the books says
"This stored procedure has been deprecated and is being supported mainly for backward-compatibility. It should only be used with Microsoft SQL Server 2000 Publishers and SQL Server 2000 republishing Subscribers."

Is there any replacement for this "This stored procedure" in SQL Server 2005?

I don't wanna use something that probably won't work with the next version of MS SQL Server

 
Hi,

I advise you to use SQL for this instead of an sp.

Code:
ALTER TABLE TEST ADD XXX nvarchar(100)

In this syntax, TEST is the table name, XXX is the column name to add nvarchar(100) is the type of column. This will work in 2000&2005 flawlessly.

Hope this helps,
ali
 
That was great, can you give me an example of removing and editing too please?

 
Nevermind, I found it


Deleting
ALTER TABLE MyTable drop column MyColumn;

Modifying -Changing the datatype (Varchar(35) is the new datatype)

Alter table MyTable modify MyColumn VARCHAR(35) ;

Modifying -Changing column's name.

Alter table MyTable change OldName NewName varchar (10) ;


 
As a clue, to get this little hints from SQL Server itself,
open Enterprise Manager, Design the table as you want but do not save it. Then click "Save change script" button from toolbar while you're in design mode. This button is the third button from left.

SQLServer will give you the SQL of the changes made...

Regards,
ali
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top