Introduction to SQLite 3 with example in Python
In this tutorial, we are going to see you how to establish the connection between SQLite 3 and python program and we also learn how to create a table through python programming.
Introduction to SQLite 3
An SQLite is a nothing but a database which has binding to several programming languages such as C, C++, Python, etc.
A simple program to create a table using SQLite in python.
before jump into the program, we have to install theĀ SQLite package. for installation flow the link:
click to know the installation process of SQLite
1st import the package :
#import the sqlite package to use all in built function of sqlite. import sqlite3
now established the connection :
#established the coonection
connec=sqlite3.connect("student.db")
print("Database has been created successfully......\n");
Create table STUDENTS:
#now create a table with name of students
connec.execute('''CREATE TABLE STUDENTS
(ROLLNO INT ,
NAME2 char(20) ,
ADDRESS2 CHAR(50)
);''')
print("STUDENTS Table has been created successfully");
and at last closed the connection:
# closed the coonection. connec.close()
The whole program single window:
#import the sqlite package to use all in built function of sqlite.
import sqlite3
#established the coonection
connec=sqlite3.connect("student.db")
print("Database has been created successfully.....\n");
#now create a table with name of students
connec.execute('''CREATE TABLE STUDENTS
(ROLLNO INT ,
NAME2 char(20) ,
ADDRESS2 CHAR(50)
);''')
print("STUDENTS Table has been created successfully");
# closed the coonection.
connec.close()
Output:
Database has been created successfully STUDENTS Table has been created successfully
Next part of this tutorial:
Also, read:
Leave a Reply