Question

In: Computer Science

Create the database with at least 10 employees and 2 managers are populated. Important: your name...

Create the database with at least 10 employees and 2 managers are populated. Important: your name should be in the employee table.

Write a Python code that can do the following:

    1) Take an employee ID from user

    2) Display the output of the SQL, select * from employee;

Improve the Python code above that can do the following:

    1) Take an employee ID from the user. Let it be idEntered.

    2) Get the departmentID for the given employeeID, idEntered. Let it be deptFound.

    3) Check if idEntered is in the table manager

    4) If yes, then execute: query = ("select * from employee where dID = %s; "). Note that since a variable deptFound is included in SQL, if it should be included, then use %s in SQL. And then declare a variable, data_tuple = (deptFound, ) in a separate line. Finally, execute the query cursor.execute(query, data_tuple).

    5) if No, simply execute the SQL: select * from employee where eid = %s; do the similarly way for idEntered as above

Solutions

Expert Solution

Hello there,Thanks For asking this question.I am here providing you all the necessary details if need more help or any Clarification. Feel free to contact me by any means necessary.

Creating Db:-

import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="root",
password=""
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE python")

Creating table:-

import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="python"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE TABLE customers (id VARCHAR(255), deptid VARCHAR(255), name VARCHAR(255))")

Code 1&2:-

import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="python"
)


mycursor = mydb.cursor()
identered= input("Enter Your Id:")
mycursor.execute("SELECT * FROM customers WHERE id LIKE %s", ("%" + user_input + "%",))

myresult = mycursor.fetchall()

for x in myresult:
print(x)

Code part 2(1,2,3&4):-

import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="python"
)


mycursor = mydb.cursor()
identered = input("Enter Your Id:-")
deptfound = input("Enter Your deptid:-")
sql="SELECT * FROM customers WHERE deptid LIKE %s"
mycursor.execute(sql,("%" + deptfound + "%",))

myresult = mycursor.fetchall()

if(mycursor.rowcount == 0):
    print("No records found for deptid Showing Result For id:- "+identered)
    sql="SELECT * FROM customers WHERE id LIKE %s"
    mycursor.execute(sql,("%" + identered + "%",))
    myresult = mycursor.fetchall()
    for x in myresult:
        print(x)
else:
    for x in myresult:
        print(x)
  


Hope it helped you,If there is any kind of error in code or it needs any modification do let me know,And please give your upvote to this it''ll encourage to do my work more efficiently.

Happy Learning!!!.


Related Solutions

PartA: Create the database. Name the database doctorWho. Then create a page that allows Doctor Who’s...
PartA: Create the database. Name the database doctorWho. Then create a page that allows Doctor Who’s assistant to add a new patient record. You will need to give the assistant rights to this database. The assistant’s username is 'helper' and the password is 'feelBetter'. For this to work, you will need to create several pages so be sure to include all of them when submitting your work. Name the main page addPatient.php. PartB: Add at least five records to the...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
Explain why the discussions with the managers and employees are important?
Explain why the discussions with the managers and employees are important?
Create a Database from blank (scratch) for a manager and name it. Create and design a...
Create a Database from blank (scratch) for a manager and name it. Create and design a table and name it. For each fields click and choose proper a data type such as short text and name the field. Make at least three fields. Enter your records. Make sure to add your name as a record. Similarly create two more tables. By design tool, make a relationship between each of two tables at a time and drag a primary key one...
Create a Web Page that has the name of at least 10 brands of dog food,...
Create a Web Page that has the name of at least 10 brands of dog food, as well as an image of each dog food. Essentially your Web Page should have 10 names and 10 Images. Start by putting a Title (ex.Good Dog Eats) at the top, and use a line separator. Then add the dog food brand names and images. You will need to “borrow” the images from some other websites like https://www.petsmart.com/ or so. Use CSS padding property...
1.Create a Database in Access with the information The database must include: Database name: Monaco Enterprise  Mark...
1.Create a Database in Access with the information The database must include: Database name: Monaco Enterprise  Mark Johnson #87451 Table name: Contacts Delete the Primary key. Fields name and data type are (remember to choose the data type): Field Name Data Types Employee Name Short text Name Short text Last Name Short Text Work Yes/No 2.Go to the “Datasheet View” and enter the data. * Remember to save the table. 3.Move the last name field after the employee name. 4.The (data)...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the relational schema created in a mini case MC5 in chapter 3. Use insert into statements to insert no fewer than 2 and no more than 10 records per table.
Create data for the purchase of an automobile.  There should be 10 automobiles in your database.  You can...
Create data for the purchase of an automobile.  There should be 10 automobiles in your database.  You can get this from the newspaper or go online and find a site that will give you some possible purchases. You should use the following fields:   Manufacturing, Model, Year, Doors, Cylinders and Sales Price. 1. Print the spreadsheet you created for your data. 2. Create and print 2 pivot tables to find some information you need to help you make your decision. 3. Do a VLOOKUP...
Name at least three current intellectual property challenges faced by IT managers, and explain how managers...
Name at least three current intellectual property challenges faced by IT managers, and explain how managers can prepare for, prevent or mitigate the damage done by each. Explain and support your argument with examples.
1. How does budgeting provide important information to managers and operating personnel? 2. Explain at least...
1. How does budgeting provide important information to managers and operating personnel? 2. Explain at least three times of budgets. 3. Explain how a flexible budget is used?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT