Creating and Deleting Tables (Relations) in PostgreSQL (using command line)

One can create and delete (drop) a table in PostgreSQL using either:

  1. pgAdmin or
  2. Command Line

Here we will be doing it using the command line.

Create Table:

We first connect to the database in which we want to create the table and then create the table using the following syntax:

create table table_name(    

    column1 datatype,

    column2 datatype, 

    ----

    columnN datatype,    

    primary key(one or more columns ));    

We use the \d command to view all tables in the current database.

Delete (drop) Table:

The command to drop a table is: drop table table_name;  

Discussion

1

0