PostgreSQL – CREATE TABLE – Query and pgAmdin

Create Table using SQL Query

To create a new table in PostgreSQL database, use sql CREATE TABLE query.

The syntax of CREATE TABLE query is:

</>
Copy
 CREATE TABLE table_name(
    column1 datatype,
    column2 datatype,
    ...
    columnN datatype
 );

where

  • table_name is the name given to the table. This table_name is used for referencing the table to execute queries on this table.
  • column1, column2,.., columnN are the column names of the table.
  • datatype s are are the respective datatypes of the columns.

Example 1 – Create a Table in PostgreSQL

In this example, we will create a PostgreSQL Table in a database, by running CREATE TABLE sql query in query tool of pgAdmin.

</>
Copy
CREATE TABLE students(
	id   INT,
	name CHAR(50),
	age  INT
)

If the CREATE TABLE query is successful, you will get a message that Query returned successfully as shown below.