3

I recently had to rename a table (and a column and FK/PK contraints) in SQL Server 2000 without losing an data. There did not seem to be an obvious DDL T-SQL statements for performing this action, so I used sp_rename to directly fiddle with object names.

Was this the only solution to the problem? (other, than give the table the correct name in the first place - doh!)

4

4 回答 4

13

sp_rename is the correct way to do it.

EXEC sp_rename 'Old_TableName', 'New_TableName'
于 2008-10-02T09:52:22.750 回答
2

Ya
EXEC sp_rename 'Old_TableName', 'New_TableName' 工作正常,但任何关键字都像“alter tabel old_name to new_name”

于 2010-06-15T08:24:50.083 回答
0

Maybe not the only: I guess you could always toy with the master database and update the table name there - but this is highly unrecommendable.

于 2008-10-02T09:55:16.317 回答
0

有一种解决方案可以让您同时使用新旧版本的表。如果您的数据被复制和/或通过客户端界面访问(这意味着旧版本的客户端界面仍将使用旧表名),这一点尤其重要:

  1. ALTER TABLE通过“ ”命令修改表上的约束(包括 FK)
  2. 不要更改表名或字段名,而是创建一个视图,例如:

    SELECT oldTable.oldField1 as newField1, ...

    将其保存为 newTable(如果需要,将其分发到不同的服务器上)


请注意,您不能以这种方式修改您的 PK。

于 2008-10-02T10:11:41.427 回答