January 2019
Beginner
318 pages
8h 23m
English
Now, we are going to create a table in our database. For that, we will create a create_table.py script and write the following content in it:
import sqlite3con_obj = sqlite3.connect("test.db")with con_obj: cur_obj = con_obj.cursor() cur_obj.execute("""CREATE TABLE books(title text, author text)""")print ("Table created")
Run the script and you will get the output as follows:
student@ubuntu:~/work $ python3 create_table.pyOutput:Table created
In the preceding example, we created a table books using a CREATE TABLE statement. First, we established a connection with our database using test.db. Next, we created a cursor object that we used to execute the SQL query on our database.
Read now
Unlock full access