简体   繁体   中英

Compound primary key in HeidiSQL

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?

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.

使用这样的命令将适用于大多数数据库

alter table myTable add constraint pkc_Id_UserID primary key (id, userid)

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

click please on the your id and select Add to index

after that select primary key ...

图片示例(对不起,葡萄牙语用户界面)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM