Search This Blog

Tuesday, February 23, 2010

How to alter a column name of a table using sql query

To update the column name of an sql table find the id of table from sysobjects table and update the syscolumns table as follows.

DECLARE @id INT
SELECT @id=[id] FROM sysobjects WHERE [name] = 'ContactDetails'

UPDATE syscolumns SET [name] ='Users_ID' WHERE [id]=@id AND [name] = 'UserID'

No comments:

Post a Comment