Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3990010
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:26:34+00:00 2026-05-20T06:26:34+00:00

I am learning mysql many to many relationship. While I was researching index, I

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:26:35+00:00Added an answer on May 20, 2026 at 6:26 am

    Your response from above lists your ALTER TABLE statement as:

    ALTER table postcategory add constraint pk_post_category(post,category);
    

    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 PRIMARY keyword. If you’re trying to add a foreign key, you’re missing the REFERENCES declaration.

    So if it’s a primary, as such, I would rewrite as:

    ALTER TABLE `postcategory` ADD CONSTRAINT PRIMARY KEY `pk_post_category` (`post`,`category`);
    

    If it’s a foreign key:

    ALTER TABLE `postcategory` ADD CONSTRAINT `fk_post_category` (`post`) REFERENCES `[tablename].[column]`;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

so..I am learning many to many relationship in mysql. I created the following tables.
I am learning to use mysql.So, I got some problems. I have three table
I am learning mysql join queries. To pratice, I decided to make tables for
I am learning mysql and I am having trouble with one of my tables
If anyone could recommend a good book for learning mySQL as well, that would
I am learning to use mysql for rails apps, and I finally have been
I am in a learning way of mysql and want help to know where
I am learning PHP and tried to connect to MySQL. Altough I am using
I'm just learning the ins and outs of MYSQL queries but I've run into
I need to run Linux-Apache-PHP-MySQL application (Moodle e-learning platform) for a large number of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.