简体   繁体   English

HeidiSQL 中的复合主键

[英]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?我想在HeidiSQL中设置“id”和“userId”为复合主键,请问这个软件可以吗?

In HeidiSQL, you would normally just click the relevant table to get into the table editor. 在HeidiSQL中,通常只需单击相关表即可进入表编辑器。 Then, select the both column names, right click, point to Create new index , then click on Primary . 然后,选择两个列名,右键单击,指向“ Create new index ,然后单击“ Primary You will see the new key appearing in the upper Indexes tab, where you can add more fields, remove it again and whatever. 您将看到新的密钥出现在上方的“ Indexes选项卡中,您可以在其中添加更多字段,再次删除它以及进行其他操作。

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

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

@anse has it correct; @anse正确无误; 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. 我还想添加您可以右键单击要添加到现有主键的新行,然后选择add to index并选择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. 或者,即使其中一些行(数据库列)已具有索引,也可以在多个行上单击鼠标左键并选择“ add to index索引”。 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. HeidiSQL将做正确的事情,只添加已更改的字段。

click please on the your id and select Add to index请单击您的 ID 并选择Add to index

after that select primary key ...之后选择primary key ...

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

just click with right button the relevant column for example 'id' and select create new index, then select PRIMARY.只需用右键单击相关列,例如“id”和 select 创建新索引,然后 select PRIMARY。 and you will see the key icon on the column you've selected.您将在所选列上看到钥匙图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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