How to rename a constraint in mysql?

5

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

CONSTRAINT PK_user_type PRIMARY KEY(id)  

But now I need to rename it to:

CONSTRAINT PK_type PRIMARY KEY(id)

Based on this, I have the following questions:

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

2 - The process for renaming a constraint of type foreign key would be the same?

3 - In the title I referred to the bank MySQl because it's what I'm currently using, but would the rename process be the same for other bank types? Such as oracle and Microsoft Sql server .

    
asked by anonymous 10.10.2018 / 22:29

1 answer

3

Can not rename a CONSTRAINT , but you can delete and create a new one:

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

For most other databases, probably most allows you to delete and re-create and the syntax should be almost the same (if it is not the same), perhaps some also support renaming

Source SOen

    
10.10.2018 / 22:47