Search:     Advanced search
Browse by category:
C/C++   |   Java   |   Oracle/Database   |   SAP   |   ASP .NET   |   Mainframe-DB2   |   Freshers

What command do we use to rename a db, a table and a column?

Add comment
Views: 59
Votes: 0
Comments: 0
To rename db

sp_renamedb ‘oldname’ , ‘newname’

If someone is using db it will not accept sp_renmaedb. In that case first bring db to single user using sp_dboptions. Use sp_renamedb to rename database. Use sp_dboptions to bring database to multi user mode.

E.g.

USE master;

GO

EXEC sp_dboption AdventureWorks, ‘Single User’, True

GO

EXEC sp_renamedb ‘AdventureWorks’, ‘AdventureWorks_New’

GO

EXEC sp_dboption AdventureWorks, ‘Single User’, False

GO

To rename Table

We can change the table name using sp_rename as follows,

sp_rename ‘oldTableName’ ’newTableName’

E.g.

sp_RENAME ‘Table_First’, ‘Table_Last’
GO

To rename Column

The script for renaming any column :

sp_rename ‘TableName.[OldcolumnName]‘, ‘NewColumnName’, ‘Column’

E.g.sp_RENAME ‘Table_First.Name’, ‘NameChange’ , ‘COLUMN’
GO
Others in this Category
document Which TCP/IP port does SQL Server run on? How can it be changed?
document What are the advantages of using Stored Procedures?
document What is Index?
document Q: What is ON DELETE CASCADE ?
document Q: What is CYCLE/NO CYCLE in a Sequence ?
document What are synonyms?
document How can we rewrite sub-queries into simple select statements or with joins?
document Q: Please explain the concepts of transaction, commit and rollback
document Q: What is difference between UNIQUE and PRIMARY KEY constraints?
document What is Dirty Read ?
» More articles



RSS