How to create a table using PostgreSQL?

How to create a table using PostgreSQL?

Syntax:

CREATE TABLE table_name (
   column1 datatype(length) column_contraint,
   column2 datatype(length) column_contraint,
   column3 datatype(length) column_contraint,
   table_constraints
);

Example 1:

CREATE TABLE interested_car (
    id SERIAL PRIMARY KEY,
    interested_car_name VARCHAR ( 50 ) NOT NULL
);

SERIAL – for auto increment

Example 2:

CREATE TABLE Account (
    Id VARCHAR( 80 ) PRIMARY KEY,
    Name VARCHAR ( 50 ) NOT NULL,
	Industry VARCHAR( 50 ),
	Rating VARCHAR( 50 ),
	Type VARCHAR( 50 ),
	AccountNumber VARCHAR( 50 ) 
);

Leave a Reply