通过SQL Server中的一个查询重命名表 [英] Rename tables through one query in sql server

查看:390
本文介绍了通过SQL Server中的一个查询重命名表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1.如何通过仅使用一个查询来重命名所有以``order_''开头的表的方式来重命名DB中的表名?

2.如何通过仅使用一个查询来重命名所有以"order_"开头的过程的方式来重命名存储过程的名称?

3.如何重命名在这些过程中更改的所有表名?

感谢所有.

1. How can i rename table names in DB by using just one query to rename all tables that start like ''order_'' ?

2. How can i rename stored procedure names by using just one query to rename all procedure that start like ''order_'' ?

3.How can i rename all tables names that changed inside these procedures ?

Thanks for all .

推荐答案

sp_rename [ ^ ]

您可以在sysobjects表中找到表和过程.

至于更改存储过程中对表的所有引用,将更加困难. T-SQL并不是字符串编辑的最佳选择.您可以创建一个托管存储过程,并使用C#处理此部分.

但是,最好的方法IMO是使用VS数据库版本或类似的工具(如果有),以便维护脚本并能够在发生任何错误的情况下进行回滚.
sp_rename[^]

You can find the tables and procedures in the sysobjects table.

As for changing all of the references to tables within the stored procedures that will be more difficult. T-SQL isn''t the best for string editing. You could create a managed stored procedure and use C# to handle this part.

However, the best approach, IMO, would be to use VS Database edition, or similar tool, if you have it so you could maintain a script and be able to rollback in case anything goes wrong.


这篇关于通过SQL Server中的一个查询重命名表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆