Create table, Create sequence

PostreSQL tutorial – Create/Alter/Drop Table

Create postgresql sequence

Create table syntax and example, Create sequence syntax.

Syntax

CREATE SEQUENCE sequence_name 
INCREMENT 1 MINVALUE 1 
MAXVALUE 9999999999999999 
START 1 CACHE 1;

Example

CREATE SEQUENCE seq_customers 
INCREMENT 1 MINVALUE 1 
MAXVALUE 9999999999999999 
START 1 CACHE 1;

Create postgresql table

Syntax

CREATE TABLE 
[IF NOT EXISTS] table_name(
column_name_1 data_type, 
column_name_2 data_type,
.......................
column_name_n data_type
);

Example

CREATE TABLE customers
(
id numeric not null 
default nextval('seq_customers'::regclass),
first_name varchar(50),
last_name varchar(50),
reg_date timestamp 
without time zone default now(),
constraint customers_pkey 
primary key (id)
);

Alter table |
Drop table