I just moved my Member
table from MRK
schema to GNR
.
I previously had the script below to set its primary key:
If not Exists (select 1
from sys.objects
where name = 'PK_MRK_Member'
)
ALTER TABLE [MRK].[Member]
ADD CONSTRAINT [PK_MRK_Member] PRIMARY KEY CLUSTERED
(
[MemberID] ASC
) ON [PRIMARY]
GO
How do I change the name AND the schema of the defined constraint now?
I tried exec sp_rename 'PK_MRK_Member', 'PK_GNR_Member', 'INDEX'
for changing the name, but get this error:
Either the parameter @objname is ambiguous or the claimed @objtype (INDEX) is wrong.
PS: I cannot drop the table and/or the PK constraint and create them again since they PK is already in use by other tables.
As I see your first parameter is wrong for procedure sp_rename
. When you rename an index you should specify the schema and table as well as index name. Check this link for example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.