Primary & Foreign Keys in pgAdmin

Mr Teeth picture Mr Teeth · Mar 15, 2012 · Viewed 62k times · Source

I was wondering can some give me an explanation on how to assign primary and foreign keys in pgAdmin?

I can't find any information online.

For example...I've got a Student table with all their details (address, d.o.b. and etc.). I'm going to add a student_number to the table and make it a primary key.

I just want to know how do I do that using pgAdmin? And if you may be kind to explain give me further information on using Primary Keys in postgreSQL (and pgAdmin). The same case with the foreign keys.

Answer

Victor Barrantes picture Victor Barrantes · Mar 3, 2014

Yes, there is a way to add Primary & Foreign Keys in pgAdmin.

Tested in pgAdmin III Ver.1.16.1 (Windows 7)

  1. Select the table you want
  2. Ctrl+Alt+Enter or right-click / Properties
  3. Select "Constraints" tab
  4. At the left-bottom side of the form you will see the option "Primary Key"
  5. Click add
  6. Select "Columns" tab
  7. Select the column you want as a key
  8. Click add

And you are all set.

You can fill more things if you want, but now you know how to get there.