Skip to content

Coder Tutorial

Menu
  • Home
  • HTML
  • CSS
  • PHP
  • SQL
  • MySQL
  • JS
  • PL/SQL
  • Python
  • Java
  • Oracle
Home
PostgreSQL
PostgreSQL Alter table add foreign key constraint to a table

PostgreSQL Alter table add foreign key constraint to a table

Add foreign key constraint to table

How to add foreign key constraint to an existing table. Constraint syntax and example.

Syntax

ALTER TABLE table_name1 
ADD CONSTRAINT fk_name
FOREIGN KEY (column_name) 
REFERENCES table_name2 (unique_column_name);

Example

ALTER TABLE customers 
ADD CONSTRAINT fk_address 
FOREIGN KEY (address_id) 
REFERENCES customer_address (id);

Tutorials

  • PostgreSQL Tutorial
  • PostgreSQL Create Table
  • PostgreSQL Drop Table
  • PostgreSQL Select
  • PostgreSQL Insert
  • PostgreSQL Update
  • PostgreSQL Delete
  • PostgreSQL Distinct
  • PostgreSQL Where
  • PostgreSQL And – Or
  • PostgreSQL Between
  • PostgreSQL Like
  • PostgreSQL Order By
  • PostgreSQL Group By
  • PostgreSQL Having
  • PostgreSQL Count
  • PostgreSQL AVG
  • PostgreSQL MAX
  • PostgreSQL MIN
  • PostgreSQL SUM
  • PostgreSQL View
  • PostgreSQL Create Function
  • PostgreSQL Create Trigger

Recent Posts

  • Java Polymorphism
  • Java Encapsulation
  • Java Abstraction
  • PostgreSQL ERROR: cannot begin/end transactions in PL/pgSQL
  • PostgreSQL Column must appear in the GROUP BY clause
  • PostgreSQL Column specified more than once
  • PostgreSQL Create database, Alter database examples
  • PostgreSQL Create schema syntax, Alter schema
  • PostgreSQL Create database user, alter and drop username
  • PostgreSQL Alter table name. Modify column name
Coder Tutorial Copyright © 2025. | Privacy Policy
Back to Top ↑