Skip to content

Coder Tutorial

Menu
  • Home
  • HTML
  • CSS
  • PHP
  • SQL
  • MySQL
  • JS
  • PL/SQL
  • Python
  • Java
  • Oracle
Home
MySQL
MySQL Add primary key

MySQL Add primary key

MySQL Add primary key

Add primary key to MySQL table using alter table syntax and primary key keyword.

MySQL Add primary key syntax

ALTER TABLE table_name ADD PRIMARY KEY (column_name);

Add primary key example

ALTER TABLE `books` ADD PRIMARY KEY (id);

Output

table `books` altered.

Tutorials

  • MySQL Tutorial
  • Database
  • Data Types
  • Insert
  • Update
  • Delete
  • Select
  • Clauses
  • Where
  • AND
  • OR
  • IN
  • Between
  • Order By
  • Limit
  • Flow Control Statements
  • CASE
  • IF
  • Iterate
  • Leave
  • Loop
  • Repeat
  • Return
  • While
  • Functions and Operators
  • Table
  • View
  • Temporary Table
  • Triggers
  • Procedure
  • Function
  • Indexes
  • Transactions
  • Create trigger
  • Create table
  • Drop table
  • Add column
  • Drop column
  • Rename column
  • Add primary key
  • Add constraint foreign key
  • Drop foreign key
  • Add index
  • Drop index

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 ↑