5
Reply

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

Rakesh Singh

Rakesh Singh

10y
2k
1
Reply

    sp_rename [ @objname = ] 'object_name' , [ @newname = ] 'new_name' [ , [ @objtype = ] 'object_type' ] Changes the name of a user-created object in the current database. This object can be a table, index, column, alias data type, or Microsoft .NET Framework common language runtime (CLR) user-defined type.For Renaming database:ALTER DATABASE "CurrentDBName" MODIFY NAME = "NewDBName"

    Hi Rakesh, Yes below commands are correct for renaming any object.To rename a Database you can use one more commandALTER DATABASE "CurrentDBName" MODIFY NAME = "NewDBName"

    To rename db sp_renamedb ‘oldname' , ‘newname' To rename Table SP_RENAME ‘oldTableName', ‘NewTableName' To rename Column sp_RENAME ‘Table_First.Name', ‘NameChange' , ‘COLUMN'

    Alter

    EXEC sys.sp_rename @objname = N'', -- nvarchar(1035)@newname = NULL, -- sysname@objtype = '' -- varchar(13)