How to rename a Constraint in mysql?

Asked

Viewed 419 times

6

I created a Constraint primary key in my table as follows:

CONSTRAINT PK_user_type PRIMARY KEY(id)  

But now I need to rename it:

CONSTRAINT PK_type PRIMARY KEY(id)

Based on this, I have the following doubts:

1 - How do I rename a constraint of the kind primary key?

2 - The process to carry out the renaming of a type Constraint foreign key would be the same way?

3 - In the title I referred to the bank MySQl because it is what I am currently using, but the renaming process would be the same for other types of banks? As for example oracle and Microsoft Sql server.

1 answer

3


Unable to rename a CONSTRAINT, but you can delete and create a new:

ALTER TABLE report_course 
    DROP PRIMARY KEY, 
    ADD CONSTRAINT `fk_report_course` PRIMARY KEY (`id`)

In relation to other databases, probably most allow to delete and create again and the syntax should be almost equal (if not equal), maybe some also have rename support

Soen source

Browser other questions tagged

You are not signed in. Login or sign up in order to post.