Skip to content

Coder Tutorial

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

PostgreSQL Alter table add primary key to existing table

Add primary key to existing table

How to add primary key to existing table. Alter syntax and example.

Syntax

ALTER TABLE tabel_name 
ADD PRIMARY KEY (column_name);

Create table

CREATE TABLE users(
  userid numeric,
  username varchar(100),
  userpass varchar(250),
  usermail varchar(50)  
  );    

Example Add primary key

ALTER TABLE users 
ADD PRIMARY KEY (userid);

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 ↑