How to make composite primary key on phpmyadmin
Asked Answered
G

2

59

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..

Gauhati answered 17/3, 2014 at 7:24 Comment(3)
this may helps you sitepoint.com/forums/…Bills
@VinodVT: No. OP's question is not that.Inculcate
@user3427877: Post your table-column structure.Inculcate
M
115

If the table is already created:

  1. 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".)
  2. Then click "Primary" in the "With selected:" list of operations just below the field names.

enter image description here

You can now also define the keys while creating the table as mentioned in @amila's answer

Millda answered 11/5, 2014 at 22:37 Comment(1)
how do you "select" a composite primary key in MySQL queries? i.e. SELECT whatever FROM whatever WHERE ????Donegan
B
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.enter image description here

Borglum answered 16/3, 2020 at 14:41 Comment(2)
Worth 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.Simpatico
Unless I'm missing something, this method isn't working in phpMyAdmin 5.2.1. Previsualizing and after creation there's only one column set as primary.Chronon

© 2022 - 2024 — McMap. All rights reserved.