The CREATE TABLE statement for PostgreSQL is used for creating a new table in any of the specified databases.
Grammar
The basic syntax for the CREATE table statement is as follows:
CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, ... .. COLUMNN datatype, or more columns));
Create TABLE is a new table that tells the database system keywords. The unique name or identity of the following table is the CREATE TABLE statement. The tables in the current database are initially empty, and commands that are issued by the owning user.
The list of each column is then defined within parentheses, and what type of data is in the table. Its syntax becomes clearer, the following example.
Instance
Here is an example that creates a student table ID as a primary key table and a NOT NULL constraint that shows that these fields cannot be null while creating records for that table:
CREATE TABLE student ( ID INT not null, NAME TEXT not null, age INT not NULL, homeaddress CHAR ( GRADE )
You can verify that the successfully created using the \d command will be used to list all the tables in the attached database.
Use the \d + table name to describe each table as follows:
CREATE table for PostgreSQL