gpt4 book ai didi

sql - sp_rename 与列有什么问题?

转载 作者:行者123 更新时间:2023-12-02 21:38:45 24 4
gpt4 key购买 nike

我正在使用以下带有 sp_rename 的 SQL 命令来重命名列。

USE MYSYS;
GO
EXEC sp_rename 'MYSYS.SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO

但它导致了错误:

Msg 15248, Level 11, State 1, Procedure sp_rename, Line 238
Either the parameter @objname is ambiguous or the claimed @objtype (COLUMN) is wrong.

请建议如何使用 sp_rename 重命名列。

[我正在使用的这个命令在 Microsoft Technet 中找到]

最佳答案

试试这个:

USE MYSYS;
GO
EXEC sp_rename 'SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO

sp_rename (Transact-SQL) (msdn):

[ @objname = ] 'object_name'

Is the current qualified or nonqualified name of the user object or data type. If the object to be renamed is a column in a table, object_name must be in the form table.column or schema.table.column. If the object to be renamed is an index, object_name must be in the form table.index or schema.table.index. If the object to be renamed is a constraint, object_name must be in the form schema.constraint.

Quotation marks are only necessary if a qualified object is specified. If a fully qualified name, including a database name, is provided, the database name must be the name of the current database. object_name is nvarchar(776), with no default.

具有完全限定名称的语法:

USE Database
GO
EXEC sp_rename 'Database.Schema.TableName.ColumnName', 'NewColumnName', 'COLUMN';
GO

如果您希望在对象名称中使用完全限定名称,您还应该指定架构。因此,如果您的 SYSDetails 表位于 dbo 架构中,则以下代码应该适合您:

USE MYSYS;
GO
EXEC sp_rename 'MYSYS.dbo.SYSDetails.AssetName', 'AssetTypeName', 'COLUMN';
GO

关于sql - sp_rename 与列有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20440347/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com