Question
PLEASE ANSWER THE QUEATONS ACCORDNG TO THE CODE BELOW Explain your company and its business. (20 points) Explain your database design, i.e. which tables and
PLEASE ANSWER THE QUEATONS ACCORDNG TO THE CODE BELOW
-
Explain your company and its business.
-
(20 points) Explain your database design, i.e. which tables and relations are used, in details.
-
(10 points) Draw ER diagram of your database1. Provide snapshots for tables.
-
(10 points) Explain keys and cardinalities for each table.
-
(20 points) Apply 4NF Normalization for your databases tables. Explain
each step of normalization.
pip install MySQLdb #Now we will import tha libraries
# Installed module we will be using to connect to MySQL database import MySQLdb Now we will connect to the database
host=
try: # Connecting to our database conn= MySQLdb.connect(host,user,password,dbname) print("Connected") conn.close() except: print("Can't connect to database") #here we can see if their is any connection error. If theirs an error we can debug the code by checking username or password.
#Also we can print(conn). If it return None then connection failed.
#Now for adding records to table
cursor=conn.cursor() # here conn is the connection object we created earlier
# Executing Query cursor.execute("insert into
cursor=conn.cursor() # here conn is the connection object we created earlier
# Executing Query cursor.execute("select * from myTable") cursor.fetchone() # Fetched the first row # OR cursor.fetchall() # Fetches all rows
# We can also pass filters to select query email = "xyz@gamil.com" cursor.execute("select * myTable where email=%s",(email)) #Additional queries
cursor=conn.cursor() # here conn is the connection object we created earlier
cursor.execute("select * from myTable limit 5") result=cursor.fetchall() # The result variable holds the records returned from using .fetchall(). Its a list of tuples representing individual records from the table. # In the query above, you use the LIMIT clause to constrain the number of rows that are received from the SELECT statement.
# Query for selected particular columns only cursor.execute("select name from myTable") result=cursor.fetchall() #Note
cursor.execute("SELECT * FROM myTable") result=cursor.fetchall()
# as we know that fetchall() return a tuple so we can use a for loop to print records one by one. for i in result: print(i)
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