Reputation: 959
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?
Upvotes: 6
Views: 8258
Reputation: 11
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.
Upvotes: 0
Reputation: 648
click please on the your id and select Add to index
after that select primary key
...
Upvotes: 1
Reputation: 1577
@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.
Upvotes: 0
Reputation: 1660
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.
Upvotes: 7
Reputation: 2016
using a command like this will work in most databases
alter table myTable add constraint pkc_Id_UserID primary key (id, userid)
Upvotes: 2