0
import sqlite3

conn=sqlite3.connect("oyo.db")

conn.execute("CREATE TABLE IF NOT EXIST OYO_HOTELS (NAME TEXT,ADDRESS TEXT,PRICE INT,AMENITIES TEXT,RATING TEXT)")
print("TEBLE CREATED SUCCESSFULLY")
conn.execute("INSERT INTO OYO_HOTELS(NAME,ADDRESS,PRICE,AMENITIES,RATING) VALUES ('OYO1','oyo1_street',450,'bath,kitchen','good')")

cur=conn.cursor()
cur.execute("SELECT * FROM OYO_HOTELS")
table_data=cur.fetchall()
for record in table_data:
    print(record)

error

conn.execute("CREATE TABLE IF NOT EXIST OYO_HOTELS (NAME TEXT,ADDRESS TEXT,PRICE INT,AMENITIES TEXT,RATING TEXT)")
sqlite3.OperationalError: near "EXIST": syntax error

2 Answers 2

1

As the error says there is a syntax error. It is EXISTS not EXIST.

conn.execute("CREATE TABLE IF NOT EXISTS OYO_HOTELS (NAME TEXT,ADDRESS TEXT,PRICE INT,AMENITIES TEXT,RATING TEXT)"
Sign up to request clarification or add additional context in comments.

Comments

0

It is the syntax error, you need to write "CREATE TABLE IF NOT EXISTS" in the place of "CREATE TABLE IF NOT EXIST".

Corrected code:

import sqlite3

conn=sqlite3.connect("oyo.db")

conn.execute("CREATE TABLE IF NOT EXISTS OYO_HOTELS (NAME TEXT,ADDRESS TEXT,PRICE INT,AMENITIES TEXT,RATING TEXT)")

print("TEBLE CREATED SUCCESSFULLY")
conn.execute("INSERT INTO OYO_HOTELS(NAME,ADDRESS,PRICE,AMENITIES,RATING) VALUES ('OYO1','oyo1_street',450,'bath,kitchen','good')")

cur=conn.cursor()

cur.execute("SELECT * FROM OYO_HOTELS")

table_data=cur.fetchall()

for record in table_data:
    print(record)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.