Little SQL Server Tricks: Rename Default Constraints

One would assume that renaming a default constraint should work the same way as renaming a primary key. For some unknown reason that was not the case as I had to fix the (dynamically generated) names of default constraints. The format that worked at last was this one:

exec sp_rename N'SCHEMA.NAME_OLD', N'NAME_NEW' , N'OBJECT';

Without the N in front of the names (that turns it explicitly into a nvarchar), I got error messages like this one:

Either the parameter @objname is ambiguous or the claimed @objtype (OBJECT) is wrong.

If you encounter reluctant constraints, try putting an N in front of the name first. Maybe it will help you too.