Friday, 5 June 2009

Renaming Objects in SQL Server

TO RENAME TABLE:
sp_rename 'T_OldTable','T_Table'
GO

TO RENAME COLUMN IN TABLE:
sp_rename 'T_Table.[OLDCOLUMNNAME]', NEWCOLUMN
go

TO RENAME DATBASE NAME:
EXEC sp_renamedb 'oldDBName', 'newDBName'
GO
ALTER DATABASE oldDBName MODIFY NAME = newDBName ---THIS OPTION AVAILABLE IN SQL SERVER 2005 AND AFTER RELEASE.
Using SQL Server Management Studio, right click on the database name and select the option "rename" and Change the New DB Name
Also you can change the database name while Detaching and Attaching:
EXEC sp_detach_db 'oldDBName', 'true'
GO
EXEC sp_attach_db @dbname = N'newDBName', @filename1 = N'D\Data\TEST_DATA.mdf', @filename2 = N'D\Data\TEST_LOG.ldf'

No comments:

Post a Comment