How to make a composite primary key on phpmyadmin. such that student id is combination of year and roll number. sid = 112132 , 11 of year 2011 and 2132 is roll number?? anybody help..
Asked
Active
Viewed 5.5k times
58
-
1this may helps you http://www.sitepoint.com/forums/showthread.php?290795-composite-key-through-phpmyadmin – Vinod VT Mar 17 '14 at 07:29
-
@VinodVT: No. OP's question is not that. – Ravinder Reddy Mar 17 '14 at 07:34
-
1@user3427877: Post your table-column structure. – Ravinder Reddy Mar 17 '14 at 07:36
2 Answers
115
If the table is already created:
- From the "Structure" pane, check the boxes to the left of all field names you want included in the primary key. (For example, in an order items table, you might check "order ID" and "line item number".)
- Then click "Primary" in the "With selected:" list of operations just below the field names.
You can now also define the keys while creating the table as mentioned in @amila's answer

Junaid
- 3,477
- 1
- 24
- 24
-
how do you "select" a composite primary key in MySQL queries? i.e. `SELECT whatever FROM whatever WHERE ????` – oldboy Nov 16 '18 at 00:53
1
Make the index of the required attributes to primary at the time of creating the table.The foloowing figure explains it in Phpmy admin.

Amila Weerasinghe
- 791
- 7
- 10
-
1Worth noting that if you already have a primary key, you can't add a second. You need to add them both at the same time. – user2924019 Oct 06 '20 at 13:21