Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# import the sqlite3 database module import sqlite3 print(SQLite Practice - Example User Table ) # create a connection to the database file conn =

# import the sqlite3 database module import sqlite3

print("SQLite Practice - Example User Table ") # 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()

Use Python

With the starting code file, build upon the program by doing the following:

Add a program title and consider the user experience throughout your output.

Modify the user table and 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 5 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.

Create two report functions of your choice and comfort level. Some suggestions for report functions include listing all users first and last names, or creating a list of names and contact information. Create an associated item in the menu so the program user can run these reports.

Build an Add User function that asks for input for the following fields and inserts a new record/row of data into your SQLite database. Be sure to add this function to the program menu.

first name

last name

email address

phone number

street address

city

state

zipcode

Use your Add User function within the program to add 5 more user records to your database.

After having 10 users in your database table, test your report functions and make sure your data is printing out properly.

Be sure to include an option to EXIT the program. The program user should be able to keep working with the menu after every option until they choose to exit the program.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago