Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename a constraint in SQL Server?

Is it possible to rename a constraint in SQL Server? I don't want to have to delete and create a new one because this constraint affects other already existing constraints and I will have to recreate/alter those.

like image 455
mezamorphic Avatar asked Jan 03 '12 13:01

mezamorphic


People also ask

Can we rename a constraint in SQL Server?

You can use the sp_rename system stored procedure to rename a CHECK constraint in SQL Server. The purpose of this stored procedure is to allow you to rename user-created objects in the current database. So you can also use it to rename other objects such as tables, columns, alias data types, etc.

How do you rename a primary key constraint in SQL Server?

In SQL Server, you can use the sp_rename stored procedure to rename a user created object in the current database, including a primary key. This can be handy if you've got a primary key that had its name automatically assigned, and you now want to give it a more readable name.

How do I rename a constraint in MySQL?

But i found the solution of mysql rename foreign key constraint using mysql query, First we have to drop the foreign key, then change the column, at last we need to again add the foreign key constraint back in column.


1 Answers

After some more digging, I found that it actually has to be in this form:

EXEC sp_rename N'schema.MyIOldConstraint', N'MyNewConstraint', N'OBJECT' 

Source

like image 164
ozz Avatar answered Oct 03 '22 12:10

ozz