尝试使用
重命名MS SQL中的密钥sp_rename 'FK_Catalog_Equipment__Equiements_Catalog_Client_Clients','FK_Catalog_Equipment__Equipments_Catalog_Client_Clients','OBJECT'
或
sp_rename 'Table_Name.FK_Catalog_Equipment__Equiements_Catalog_Client_Clients','FK_Catalog_Equipment__Equipments_Catalog_Client_Clients','OBJECT'
但两个命令都会导致
Msg 15248, Level 11, State 1, Procedure sp_rename, Line 359
Either the parameter @objname is ambiguous or the claimed @objtype (OBJECT) is wrong.
我做错了什么?
答案 0 :(得分:8)
外键约束是单个对象,这就是为什么你不能拥有与其他对象同名的FK。因此,它们的名称与架构相关。
从sp_rename's documentation示例中复制:
sp_rename 'HumanResources.FK_Employee_Person_BusinessEntityID', 'FK_EmployeeID';
会将FK_Employee_Person_BusinessEntityID
架构中的HumanResources
重命名为FK_EmployeeID
如果缺少架构,SQL Server将在用户的默认架构中查找对象,该架构通常是dbo
架构。如果在不同的模式中创建FK,则需要明确指定它
答案 1 :(得分:3)
试试这个
exec sp_rename '<SchemaName>.FK_Catalog_Equipment__Equiements_Catalog_Client_Clients',
'FK_Catalog_Equipment__Equipments_Catalog_Client_Clients', 'object'
有关详细信息click here
否则删除约束,然后重命名,然后添加约束是一种简单的方法。虽然成本很高,因为创建新约束必须验证现有数据。
ALTER TABLE <TableName>
DROP FOREIGN KEY 'FK_Catalog_Equipment__Equiements_Catalog_Client_Clients',
ADD CONSTRAINT `FK_Catalog_Equipment__Equipments_Catalog_Client_Clients`
FOREIGN KEY (`<tag_id>`) REFERENCES `tags` (`<id>`);