postgresql add table code example
Example 1: create table in postgresql
CREATE TABLE accounts (
user_id serial PRIMARY KEY,
username VARCHAR ( 50 ) UNIQUE NOT NULL,
password VARCHAR ( 50 ) NOT NULL,
email VARCHAR ( 255 ) UNIQUE NOT NULL,
created_on TIMESTAMP NOT NULL,
last_login TIMESTAMP
);
Example 2: postgres create table
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
Example 3: postgres how to add field created at
CREATE TABLE my_table
(
id serial NOT NULL,
user_name text,
created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP
)
Example 4: alter table add column postgres
Alter Postgres Table