March 3, 2011 at 5:35 am
I have a table in an DB called admin (dbo.admin)
I want to change the name to administration (dbo.administration)
How to script this change?
I found 'Rename', and tried:
ALTER TABLE dbo.admin
RENAME TO administrator
But it does not look like MSSQL 2005 knows the word RENAME
Best regards
Edvard Korsbæk
March 3, 2011 at 5:43 am
edvard 19773 (3/3/2011)
I have a table in an DB called admin (dbo.admin)I want to change the name to administration (dbo.administration)
How to script this change?
I found 'Rename', and tried:
ALTER TABLE dbo.admin
RENAME TO administrator
But it does not look like MSSQL 2005 knows the word RENAME
Best regards
Edvard Korsbæk
Try this:
create table OldName(
Col1 int
)
sp_rename 'OldName', 'NewName'
-Ki
-Ki
March 3, 2011 at 5:47 am
RENAME is the oracle command to do what you are asking.
in sql server, a stopred procedure is used:
EXEC sp_rename 'admin','administration'
or
EXEC sp_rename 'dbo.admin','administration'
note the first parameter can accept just the tablename, or the schemaname.tablename in order to clearly identify which object, and the second parameter is just the tablename...
if you do this:
EXEC sp_rename 'dbo.admin','dbo.administration'
yould end up with a wierd tablename you must selec twith SELECT * FROM dbo.[dbo.administration]
Lowell
March 3, 2011 at 5:47 am
Use the system stored procedure sp_rename...
sp_rename 'old name', 'new name'
March 3, 2011 at 5:51 am
Testet - Works like a charm!
Thanks
Edvard Korsbæk
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply