A
Aryan Sharma

Posted on 14th May 2024|132 views

0
votes

Postgresql Create Table If Not Exists

How to create a table if that doesn't exist in PostgreSQL?

Answers
P
veerubhotla sowmithri

Posted on 14th May 2024

  • First, we use the Create Table statement to create a table in the PostgreSQL.
  • Now name the table_name.
  • Now by providing columns with column names, type of data to be stored in columns and size of the columns in parentheses(size).
  • The primary key defines a record, so it points a table or set of information.

CREATE DATABASE employee_details;

CREATE TABLE employee_data(

id INT not null,

name VARCHAR(20) unique not null,

dob DATETIME not null,

email VARCHAR(40) unique,

created_on TIMESTAMP not null,

last_login TIMESTAMP

Primary key(id)

);

 

Output:

Column_name Column_type      
Size
(KEY) id Int  Not null
name varchar 20
dob datetime Not null
email varchar 40
created_on Timestamp Not null
Last_login Timestamp Not null

 

 

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo
  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos