Question
This is to be coded in Python Console # import the sqlite3 database module import sqlite3 # create a connection to the database file conn
This is to be coded in Python Console
# import the sqlite3 database module
import sqlite3
# create a connection to the database file
conn = sqlite3.connect("myDatabase.db")
# create a cursor that we will use to move through the database
cursor = conn.cursor()
# check if the user table already exists, if so, drop it so we can start with a new table
cursor.execute("DROP TABLE IF EXISTS user;")
# create the table if it doesn't already exist
# note that primary keys are automatically created in sqlit3 and referenced as rowid
cursor.execute("CREATE TABLE user (first_name TEXT, last_name TEXT, email TEXT)")
# create some records of data
cursor.execute("INSERT INTO user VALUES (\"Tony\", \"Stark\", \"ironman@stark.com\")")
cursor.execute("INSERT INTO user VALUES (\"Carol\", \"Danvers\", \"marvel@stark.com\")")
# query the table including the rowid primary key value
cursor.execute("SELECT rowid, first_name, last_name, email FROM user")
# store the results of a the query to a list called users
users = cursor.fetchall()
# now we can loop through the results of the query
for this_user in users:
print(this_user[0], this_user[1], this_user[2], this_user[3])
# save the updates to the database - if you don't commit any updates/inserts to the database will not be saved
conn.commit()
# close the connection
conn.close()
Using the example above, create a user table and be sure to create columns/fields to store the following information: first name, last name, email address, phone number, street address, city, state, zipcode.
Populate your table with at least 10 records of unique data. Feel free to keep to a theme like I have (Marvel) or whatever theme you would like.
Create a menu for the user to interact with your data by creating functions that will perform different SQL SELECT queries. Build at least three functions of your choice and comfort level. Some functions include listing all users first and last names, or creating a list of names and contact information. Consider the user experience.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started