Compound primary key in HeidiSQL
Asked Answered
C

5

6

I have a table which contains many fields. I'd like to set "id" and "userId" as a composite primary key in HeidiSQL, do you know if it is possible with this software?

Confute answered 12/8, 2014 at 15:3 Comment(0)
H
7

In HeidiSQL, you would normally just click the relevant table to get into the table editor. Then, select the both column names, right click, point to Create new index, then click on Primary. You will see the new key appearing in the upper Indexes tab, where you can add more fields, remove it again and whatever.

Hairless answered 10/12, 2015 at 8:20 Comment(0)
C
2

using a command like this will work in most databases

alter table myTable add constraint pkc_Id_UserID primary key (id, userid)
Crucial answered 12/8, 2014 at 15:35 Comment(0)
E
1

click please on the your id and select Add to index

after that select primary key...

Electrocardiograph answered 3/1, 2022 at 9:24 Comment(0)
N
0

@anse has it correct; I'd also like to add you can right click on the new row you want to add to an existing primary key, then select add to index and choose the Primary Key if you already have a primary key defined and want to create a compound primary key.

Or, you can shift click on multiple rows and also select add to index even if some of those rows (database columns) already have indexes. At first, I removed the single index, then added the two, but you can skip this step; HeidiSQL will do the right thing and only add the fields that changed.

Nighthawk answered 14/9, 2019 at 5:20 Comment(0)
R
0

 image example (sorry for the portuguese UI)

just click with right button the relevant column for example 'id' and select create new index, then select PRIMARY. and you will see the key icon on the column you've selected.

Reciprocate answered 9/1, 2023 at 2:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.