MySQL

How to create composite primary key in MySQL PHPMyAdmin

In this tutorial, we are going to see how to create a composite primary key in MySQL PHPMyAdmin. In MySQL, a primary key is a single field or a combination of fields that uniquely defines a record. None of the fields in the primary key can contain NULL value. In MySQL, a table can have only one primary key.
 

How to create composite primary key in MySQL & PHPMyAdmin

1. First open PHPMyAdmin in your browser on the url http://127.0.0.1/phpmyadmin. Then select the database, in which you want to create a composite primary key.
 

 
xxxx
 
2. In this tutorial, we are going to select the ‘gallery’ database, which contains the ‘gallery’ table. So click “Structure” from the menu at the top.
 

 
3. Now click on “Structure” from the “Action” column.
 

 
 
4. First check the boxes of the fields you want to include in the primary key. Then click the “Primary” button in the list of operations just below the fields. Here in this example we have checked the two column (‘id’ and ‘hash’).
 

 
5. You should get a message like below:
 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *