top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

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

0 votes
472 views
What command do we use to rename a db, a table and a column?
posted Nov 26, 2014 by Vinitha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

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
answer Nov 26, 2014 by Manikandan J
Similar Questions
+1 vote

I have a simple mapping that reads data from a SQL Server table with a column of type 'money'. The column is mapped to another table with the column of type decimal 19,4. (Informatica converts type money to type decimal 19,4.) When running the workflow, no rows are inserted into the target table, and no meaningful errors are produced. However the data is inserted correctly when the money column mapping is deleted.

Looking at the session log, it appears Informatica believes the rows were inserted correctly.

How can I correctly map the money column to a SQL server table.

...