I am learning mysql many to many relationship. While I was researching index, I found the below question.
How to properly index a linking table for many-to-many connection in MySQL?
Quassnoi answered a detail answer. Within his answer, I found the following syntax.
“ALTER TABLE table_table ADD CONSTRAINT pk_table1_table2 (table_1, table_2)”
I changed “table_table” to my joining table called “postcategory” and changed “table1” to “post”, “table2” to “category”
I got a syntax error when I execute it..
What am I doing wrong? I think I didn’t understand Quassnoi’s intention perfectly.
Your response from above lists your
ALTER TABLEstatement as:You’re defining a constraint here, not an index. If you’re trying to add a primary key, it probably shouldn’t be multicolumn (composite) and if so, you’re missing the
PRIMARYkeyword. If you’re trying to add a foreign key, you’re missing theREFERENCESdeclaration.So if it’s a primary, as such, I would rewrite as:
If it’s a foreign key: