24

I have a PK constraint on table Notes named PK_dbo.Notes and want to rename it to PK_Notes using SQL Server DDL, i.e. not by using SSMS rename menu option.

Mentioned in another question's answers queries don't work for me. That thread's answers are also helpful, but don't work too.

Community
  • 1
  • 1
pkuderov
  • 3,501
  • 2
  • 28
  • 46

1 Answers1

42

Sometimes you need to explicitly wrap names in square brackets, like this:

sp_rename @objname = N'[Notes].[PK_dbo.Notes]', @newname = N'PK_Notes'

I think it's because of the dot in PK name.

Also, as you see, PK constraints don't need @objtype = 'OBJECT' to be specified.

pkuderov
  • 3,501
  • 2
  • 28
  • 46