World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Designed by IITians, only for AI Learners.
New to InsideAIML? Create an account
Employer? Create an account
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
559 Learners
Neha Kumawat
a year ago
DROP TABLE table_name;
postgres=# CREATE TABLE CRICKETERS (
First_Name VARCHAR(255), Last_Name VARCHAR(255), Age int,
Place_Of_Birth VARCHAR(255), Country VARCHAR(255)
);
CREATE TABLE
postgres=#
postgres=# CREATE TABLE EMPLOYEE(
FIRST_NAME CHAR(20) NOT NULL, LAST_NAME CHAR(20),
AGE INT, SEX CHAR(1), INCOME FLOAT
);
CREATE TABLE
postgres=#
postgres=# \dt;
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | cricketers | table | postgres
public | employee | table | postgres
(2 rows)
postgres=#
postgres=# DROP table employee;
DROP TABLE
postgres=# \dt;
List of relations
Schema | Name | Type | Owner
--------+------------+-------+----------
public | cricketers | table | postgres
(1 row)
postgres=#
postgres=# DROP table employee;
ERROR: table "employee" does not exist
postgres=#
postgres=# DROP table IF EXISTS employee;
NOTICE: table "employee" does not exist, skipping
DROP TABLE
postgres=#
import psycopg2
#establishing the connection
conn = psycopg2.connect(database="mydb", user='postgres', password='password', host='127.0.0.1', port= '5432')
#Setting auto commit false
conn.autocommit = true
#Creating a cursor object using the cursor() method
cursor = conn.cursor()
#Doping EMPLOYEE table if already exists
cursor.execute("DROP TABLE emp")
print("Table dropped... ")
#Commit your changes in the database
conn.commit()
#Closing the connection
conn.close()
Table dropped...