如何在 SQL Server 中重命名表? [英] How to rename a table in SQL Server?

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

问题描述

我使用的 SQL 查询是:

ALTER TABLE oldtable RENAME TO newtable;

但是,它给了我一个错误.

But, it gives me an error.

服务器:消息 156,级别 15,状态 1,第 1 行
关键字TO"附近的语法不正确.

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'TO'.

推荐答案

要在 SQL Server 中重命名表,请使用 sp_rename 命令:

To rename a table in SQL Server, use the sp_rename command:

exec sp_rename 'schema.old_table_name', 'new_table_name'

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

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