SQL CREATE ALTER DROP TABLE

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

Internal

Overview

CREATE

CREATE [TEMPORARY] TABLE person 
( id smallint, 
  name varchar(30) NOT NULL, 
  CONSTRAINT pk_person PRIMARY KEY (id)
);
PostgreSQL MySQL

If the TEMPORARY keyword is used, the created table will be temporary instead of permanent.

ALTER

ALTER TABLE person [...]

Add/Remove a Column

ALTER TABLE person ADD COLUMN birthday DATE;
ALTER TABLE person DROP COLUMN birthday;
PostgreSQL MySQL

Add/Remove a Constraint

NOT NULL

ALTER TABLE sometable ALTER COLUMN somecolumn SET NOT NULL;
ALTER TABLE sometable ALTER COLUMN somecolumn DROP NOT NULL;
PostgreSQL MySQL

Primary Key

PostgreSQL MySQL

DROP

DROP TABLE person [...]
PostgreSQL MySQL

Features

AUTO_INCREMENT

AUTO_INCREMENT