Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compound primary key in HeidiSQL

Tags:

sql

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?

like image 498
mark Avatar asked Aug 12 '14 15:08

mark


People also ask

How to create a primary index in HeidiSQL?

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.

How to create composite primary key in MySQL?

Here are the steps to create composite primary key in MySQL. You can create composite primary key, either during table creation using CREATE TABLE statement, or after creating tables using ALTER TABLE statement. We will look at both these examples to create composite primary key in MySQL.

How to view table foreign keys with HeidiSQL?

In this tutorial I'd like to show you how to view table foreign keys with HeidiSQL. To see table FKs first select table in the object explorer, then select Table tab, and under this tab select Foreign keys tab. All table foreign keys will be visible in the list on the upper part of the window.

What is a composite key in SQL?

A composite key is a key that is the combination of more than one attribute or column of a given table. It may be a candidate key or a primary key. Attention reader!


3 Answers

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.

like image 156
Anse Avatar answered Sep 30 '22 10:09

Anse


using a command like this will work in most databases

alter table myTable add constraint pkc_Id_UserID primary key (id, userid)
like image 41
bowlturner Avatar answered Sep 30 '22 08:09

bowlturner


click please on the your id and select Add to index

after that select primary key...

like image 21
Saeid Avatar answered Sep 30 '22 09:09

Saeid