skip to Main Content

I am new to programming and still learning. I have a project which is developed using PHP and MySQL. I’m facing an issue in SQL where I wanted to drop the primary key for the table I created. It would be helpful for me if anyone can help me on this.

This is my query:

ALTER TABLE `contract_extension_survey` DROP PRIMARY KEY `worker_id`;

2

Answers


  1. To drop a primary key column in MySQL, you want to use the following syntax:

    ALTER TABLE table_name
    DROP PRIMARY KEY;
    

    So in your case it would be something like:

    ALTER TABLE contract_extension_survey
    DROP PRIMARY KEY;
    
    Login or Signup to reply.
  2. From DROP INDEX Statement

    To drop a primary key, the index name is always PRIMARY, which must be
    specified as a quoted identifier because PRIMARY is a reserved word:

    In your case ,

    DROP INDEX `PRIMARY` ON contract_extension_survey;
    

    Or written a little longer

    ALTER TABLE contract_extension_survey DROP  PRIMARY KEY;
    

    See example

    See Primary Keys and Indexes

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search