SQL Overview The directory contains a file people_info.csv. The columns are first_name middle_name last_name email employee_type,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
SQL Overview The directory contains a file people_info.csv. The columns are first_name middle_name last_name email employee_type, which can be one of Professor, Lecturer, Staff. The value is empty if the person is a student. enrollment_year which must be in the range 2016-2023. The value is empty if the person is an employee. If enrollment_year is not NULL, the person is a Student and employee_type must be NULL. If employee_type is not NULL, then the person is a Employee and enrollment_year must be NULL. [33]: %%sql You must implement a two-table solution to the inheritance pattern. This means that your solution will have tables student and employee, and have a view people. You must demonstrate correct implementation by loading the data, using select statements, attempting insert/update/delete, ... [33] [] DROP SCHEMA IF EXISTS f23_hw2; CREATE SCHEMA f23_hw2; USE f23_hw2; * mysql+pymysql://root:***@localhost 5 rows affected. 1 rows affected. 0 rows affected. Tables and View You must implement the two tables and view, including reasonable data types and constraints. This must include an additional column uni that we explain below. You may add additional columns and triggers if that helps. 1. uni is the primary key. 2. employee_type must be one of Professor, Lecturer, Staff. 3. enrollment_year must be in the range 2016-2023 inclusive. 4. Only middle name can be null. 5. email must be unique over both student and employee. Note that this constraint should be checked when inserting new rows and updating existing rows. [34]: %%sql UNI uni: 1. Must be of the form fml####, where f is the first letter (lowercased) of the first name, m is the first letter of the middle name (if not NULL), 1 is the first letter of the last name, and #is a number. 2. For any combination of letters, the numbers following the letters must start at 1 and increase. That is, dff0001, ab0001, dff0002, cd0001, cad0001, cd0002, ... 3. You must implement a function to generate the uni. 4. You must implement triggers on the relevant tables to automatically set the uni during an insert. 5. You must implement triggers that adjust the uni if a person's initials change during an update. 6. You must implement logic that prevent inserts from directly setting the uni and updates from directly changing the uni. [ ]: %%sql Procedures You must implement four stored procedures. The implementations of the four procedures are almost identical. 1. The procedures are: A. create student (first_name, middle_name, last_name, email, enrollment_year, uni) B. create employee (first_name, middle_name, last_name, email, employee_type, uni) [ ]: %%sql C. update student (uni, first_name, middle_name, last_name, email, enrollment_year) D. update employee (uni, first_name, middle_name, last_name, email, employee_type) 2. For updates, the procedures ignore input parameters that are NULL and only apply the non-NULL values. The procedures do not update the uni. 3. The create procedures return the uni as an out value. Security You must create a new user general_user and use security to allow it to perform only SELECT and EXECUTE operations (i.e., no INSERT, DELETE, and UPDATE operations). [ ]: %%sql Data Insertion []: %%sql # The following assumes that you have created everything properly DELETE FROM f23_ hw2.student; DELETE FROM f23_hw2.employee; []: people_info = [] with open ("people_info.csv", "r") as in file: d_rdr = csv.DictReader (in_file) for r in d_rdr: people_info.append(dict(r)) people_info_df = pd.DataFrame (people_info) people_info_df [ ]: # If you have defined your procedures, functions, tables, and constraints correctly, you can use the function below # to load your data. def add_person (p): p is a dictionary containing the column values for either a student or an employee. www cur= sql_conn.cursor() # This function changes the data, converting to None. # So, we make a copy and change the copy. p_dict copy.copy(p) = for k, v in p_dict.items(): if v == : p_dict [k] = None # Is the person a student? # if p_dict['employee_type'] is None: # This provides a hint for what your stored procedure will look like. res = cur.callproc("f23_hw2.create_student", else: # The following are in parameters (p_dict['first_name'], # After the procedure executes, the following query will select the out values. res = cur.execute("""SELECT @_f23_hw2.create_student_5""") result = cur.fetchall() p_dict ['middle_name'], p_dict [last_name'], p_dict['email'], #The following does the same for employee. elif p_dict['enrollment_year'] is None: res = cur.callproc("f23_hw2.create_employee", p_dict['enrollment_year'], #The following are out parameters for uni. None)) sql_conn.commit() cur.close() return result []: for p in people info: add_person (p) res = cur.execute("""SELECT @_f23_hw2.create_student_5""") result= cur.fetchall(). (p_dict['first_name'],' p_dict ['middle_name'], p_dict [last_name'], p_dict ['email'l, p_dict ['employee_type'], None)) print("Something went wrong") result = None []: # Test that we loaded people %sql SELECT * FROM people []: # Test that we loaded students. %sql SELECT* FROM student []: # Test that we loaded employees $sql SELECT * FROM employee 1: 1: Testing Add your tests below. You should test 1. Successful execution of each procedure. 2. Execution of update procedures showing that your constraints prevent incorrect data entry and enforce the defined semantics and behavior. 3. general user can query the data and call the procedures, but cannot perform INSERT, UPDATE, or DELETE. SQL Overview The directory contains a file people_info.csv. The columns are first_name middle_name last_name email employee_type, which can be one of Professor, Lecturer, Staff. The value is empty if the person is a student. enrollment_year which must be in the range 2016-2023. The value is empty if the person is an employee. If enrollment_year is not NULL, the person is a Student and employee_type must be NULL. If employee_type is not NULL, then the person is a Employee and enrollment_year must be NULL. [33]: %%sql You must implement a two-table solution to the inheritance pattern. This means that your solution will have tables student and employee, and have a view people. You must demonstrate correct implementation by loading the data, using select statements, attempting insert/update/delete, ... [33] [] DROP SCHEMA IF EXISTS f23_hw2; CREATE SCHEMA f23_hw2; USE f23_hw2; * mysql+pymysql://root:***@localhost 5 rows affected. 1 rows affected. 0 rows affected. Tables and View You must implement the two tables and view, including reasonable data types and constraints. This must include an additional column uni that we explain below. You may add additional columns and triggers if that helps. 1. uni is the primary key. 2. employee_type must be one of Professor, Lecturer, Staff. 3. enrollment_year must be in the range 2016-2023 inclusive. 4. Only middle name can be null. 5. email must be unique over both student and employee. Note that this constraint should be checked when inserting new rows and updating existing rows. [34]: %%sql UNI uni: 1. Must be of the form fml####, where f is the first letter (lowercased) of the first name, m is the first letter of the middle name (if not NULL), 1 is the first letter of the last name, and #is a number. 2. For any combination of letters, the numbers following the letters must start at 1 and increase. That is, dff0001, ab0001, dff0002, cd0001, cad0001, cd0002, ... 3. You must implement a function to generate the uni. 4. You must implement triggers on the relevant tables to automatically set the uni during an insert. 5. You must implement triggers that adjust the uni if a person's initials change during an update. 6. You must implement logic that prevent inserts from directly setting the uni and updates from directly changing the uni. [ ]: %%sql Procedures You must implement four stored procedures. The implementations of the four procedures are almost identical. 1. The procedures are: A. create student (first_name, middle_name, last_name, email, enrollment_year, uni) B. create employee (first_name, middle_name, last_name, email, employee_type, uni) [ ]: %%sql C. update student (uni, first_name, middle_name, last_name, email, enrollment_year) D. update employee (uni, first_name, middle_name, last_name, email, employee_type) 2. For updates, the procedures ignore input parameters that are NULL and only apply the non-NULL values. The procedures do not update the uni. 3. The create procedures return the uni as an out value. Security You must create a new user general_user and use security to allow it to perform only SELECT and EXECUTE operations (i.e., no INSERT, DELETE, and UPDATE operations). [ ]: %%sql Data Insertion []: %%sql # The following assumes that you have created everything properly DELETE FROM f23_ hw2.student; DELETE FROM f23_hw2.employee; []: people_info = [] with open ("people_info.csv", "r") as in file: d_rdr = csv.DictReader (in_file) for r in d_rdr: people_info.append(dict(r)) people_info_df = pd.DataFrame (people_info) people_info_df [ ]: # If you have defined your procedures, functions, tables, and constraints correctly, you can use the function below # to load your data. def add_person (p): p is a dictionary containing the column values for either a student or an employee. www cur= sql_conn.cursor() # This function changes the data, converting to None. # So, we make a copy and change the copy. p_dict copy.copy(p) = for k, v in p_dict.items(): if v == : p_dict [k] = None # Is the person a student? # if p_dict['employee_type'] is None: # This provides a hint for what your stored procedure will look like. res = cur.callproc("f23_hw2.create_student", else: # The following are in parameters (p_dict['first_name'], # After the procedure executes, the following query will select the out values. res = cur.execute("""SELECT @_f23_hw2.create_student_5""") result = cur.fetchall() p_dict ['middle_name'], p_dict [last_name'], p_dict['email'], #The following does the same for employee. elif p_dict['enrollment_year'] is None: res = cur.callproc("f23_hw2.create_employee", p_dict['enrollment_year'], #The following are out parameters for uni. None)) sql_conn.commit() cur.close() return result []: for p in people info: add_person (p) res = cur.execute("""SELECT @_f23_hw2.create_student_5""") result= cur.fetchall(). (p_dict['first_name'],' p_dict ['middle_name'], p_dict [last_name'], p_dict ['email'l, p_dict ['employee_type'], None)) print("Something went wrong") result = None []: # Test that we loaded people %sql SELECT * FROM people []: # Test that we loaded students. %sql SELECT* FROM student []: # Test that we loaded employees $sql SELECT * FROM employee 1: 1: Testing Add your tests below. You should test 1. Successful execution of each procedure. 2. Execution of update procedures showing that your constraints prevent incorrect data entry and enforce the defined semantics and behavior. 3. general user can query the data and call the procedures, but cannot perform INSERT, UPDATE, or DELETE.
Expert Answer:
Related Book For
Concepts of Database Management
ISBN: 978-1285427102
8th edition
Authors: Philip J. Pratt, Mary Z. Last
Posted Date:
Students also viewed these databases questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
answer the question clearly You are building a flight-control system for which a convincing safety case must be made. Would you assign the tasks of safety requirements engineering, test case...
-
Among the 3 dimensioning techniques A, B and C, which one is correct. 50 50 A B 50 C
-
Since the 1960s, the Free Expression Tunnel at North Carolina State University has been the University's way to combat graffiti on campus. The tunnel is painted almost daily by various student groups...
-
For what reasons might a company like IBM repurchase some of its stock (treasury stock)?
-
A useful expansion is Use this to express the exponential in equation (13.20) in linear terms of powers of \(\Delta t\) up to first order. Note that this differs from the expression in (13.19), so...
-
Hewitt Companys output for the current period yields a $30,000 favorable overhead volume variance and a $50,400 unfavorable overhead controllable variance. Standard overhead charged to production for...
-
10.a. (4 points) Assuming that you have a wired and a wireless network with the same link capacity and total demand, why are collisions more likely to occur on the wireless network as compared to the...
-
The Armory Committee was composed of officers from various National Guard units. It organized a New Years Eve dance at a charge of $2 per person to defray costs. Perry, along with others, was a...
-
Q1- An engineering student is trying to create a new drivetrain system for his bike, consisting of a pully system. Pully A is connected to pully B by a non-slip belt and pully B is rigidly attached...
-
If the clothing maker bought 500 m of this fabric, how much money did he lose? Use 1 tepiz = 0.625 dollar and 0.9144 m = 1 yard Express your answer in dollars using two significant figures.
-
9- Below a Covid-19 test is described. The test is applied to 704 patients and for this group if 18 infected person are classified as healthy, how many people are healthy but classified as infected?...
-
Time left 0:49:40 The work done by a net external force on a system is 36J and the work done by a frictional force acting on the system is -12.J. The change in the mechanical energy is Oa 12J O b....
-
10. Color Doppler ultrasound devices are often used to assess the health of the fetal heart during pregnancy. During a fetal ultrasound exam, a transducer placed against the expectant mother abdomen...
-
Polarization of Light #9 Light that has already passed through one polarizing filter has an intensity of 2.0 W/m. If that light then passes through a second polarizer, how should it be aligned so...
-
A cantilever beam 3 m long and 10x20 cm in cross section carries a point load of (2000+roll number) at its free end. Determine the deflection at its free end. E = 2x10 kg/cm?
-
Transform the while loop from the previous exercise into an equivalent for loop (make sure it produces the same output).
-
Define a view named Item Order. It consists of the item number, description, price, order number, order date, number ordered, and quoted price for all order lines currently on file. a. Using SQL,...
-
How do you indicate criteria in an Access query?
-
The requirements shown in Question 11 have changed. The dentists office would like to add the date of the patients last payment. In which relation (table) would you place this attribute? Why? Data...
-
Sumitomo Cable manufactures various types of aluminum and copper cables which it sells directly to retail outlets through its distribution channels. The manufacturing process for producing cables...
-
The Cooper Furniture Company of Potomac, Maryland, assembles two types of chairs (Recliners and Rockers). Separate assembly lines are used for each type of chair. Classify each cost item (AI) as...
-
The following data are for Marvin Department Store. The account balances (in thousands) are for 2017. 1. Compute (a) the cost of goods purchased and (b) the cost of goods sold. 2. Prepare the income...
Study smarter with the SolutionInn App