You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CREATETABLEtable_name(
Column_name + data_type + constraints if any
)
Example
CREATETABLEperson(
id int,
firstName VARCHAR(40),
lastName VARCHAR(40),
gender VARCHAR(6),
dateOfBirth DATE
);
\d /* Describe the all relations */
\d person /* Desribe table */
Before creating the table you need to grant permissions to the user.
GRANT CONNECT ON DATABASE testdatabase TO neerajkumar; /* Connect permission */GRANT pg_read_all_data TO neerajkumar; /* Read Permission */GRANT pg_write_all_data TO neerajkumar; /* Write permission */GRANT USAGE ON SCHEMA public TO neerajkumar; /* Schema usage permission */GRANT postgres TO neerajkumar; /* You can grant specfic role from other user as well */
Creating Table with Constaints
CREATETABLEperson(
id BIGSERIALNOT NULLPRIMARY KEY, /* BIGSERIAL will increment value itself */
firstName VARCHAR(40) NOT NULL,
lastName VARCHAR(40) NOT NULL,
gender VARCHAR(6) NOT NULL,
dateOfBirth DATENOT NULL
);
/* Alter table, if you want to add anther column in schema */ALTERTABLE person
ADD COLUMN email VARCHAR(30);