Programmatically renaming a table in SQL Server 2000 - is this the only sp_rename solution?

I recently had to rename a table (and column and FK / PK) in SQL Server 2000 without losing data. Apparently, there were no obvious T-SQL DDL statements to complete this action, so I used sp_rename to directly script with the names of the objects.

Was this the only solution to the problem? (other than giving the correct table name is doh!)

+3
source share
4 answers

sp_rename is the right way to do this.

EXEC sp_rename 'Old_TableName', 'New_TableName'
+13
source

.
EXEC sp_rename 'Old_TableName', 'New_TableName' , , "alter tabel old_name to new_name"

+2

, : , , .

0

, . , / ( , - ):

  • ( FK) ALTER TABLE
  • , :

    SELECT oldTable.oldField1 as newField1, ...

    newTable (, , )


, .

0

Source: https://habr.com/ru/post/1697807/


All Articles