0 votes
in Python by
How to create Tables in python?

1 Answer

0 votes
by

sqlite3 is available by default in Python standard library and hence there is no need of installing it separately.

SQLite is a very lightweight database. You can connect to it directly, with minimal settings.

Creating a Sample Table
Example 1
import sqlite3
# establishing  a database connection
con = sqlite3.connect('D:\\TEST.db')
# preparing a cursor object
cursor = con.cursor()
# preparing sql statements
sql1 = 'DROP TABLE IF EXISTS EMPLOYEE'
sql2 = '''
       CREATE TABLE EMPLOYEE (
       EMPID INT(6) NOT NULL,
       NAME CHAR(20) NOT NULL,
       AGE INT,
       SEX CHAR(1),
       INCOME FLOAT
       )
      '''
# executing sql statements
cursor.execute(sql1)
cursor.execute(sql2)
# closing the connection
con.close()

Related questions

0 votes
asked May 16, 2020 in Python by Robindeniel
0 votes
asked Oct 30, 2020 in Python by sharadyadav1986
...