Question: Hello! Help me with SQL , please! We have following tables from database _ adventureworkslt: CREATE TABLE plan _ status ( quarterid varchar ( 6

Hello! Help me with SQL, please!
We have following tables from database _adventureworkslt:
CREATE TABLE plan_status (
quarterid varchar(6) NOT NULL,
status varchar(10) NOT NULL,
modifieddatetime timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
author varchar(20) DEFAULT CURRENT_USER NOT NULL,
country varchar(5) NOT NULL,
CONSTRAINT plan_status_pk PRIMARY KEY (quarterid, country)
);
CREATE TABLE country_managers (
username varchar(30) NOT NULL,
country varchar(5) NOT NULL,
CONSTRAINT country_managers_pk PRIMARY KEY (username, country)
);
Write two functions in python:
set_lock(year, quarter, user, pwd), which will change status from R to L for records in
plan_status, that are associated with the target quarter and year, and connected to the current
user in the country_managers configuration table. To obtain the name of the current user, use
current_user. Also write a timestamp of modification to the modifieddatetime field.
remove_lock(year, quarter, user, pwd) function, that will change the planning data status from
L to R. associated with the current user through the country_managers table. Also update the
modifieddatetime field.
Execute the set_lock function to lock the plan data for the 1st quarter of 2014 on behalf of Kirill user,
and then Sophie. If everything is done correctly, data will appear in the v_plan_edit view if
connected as Kirill or Sophie.
Increase the planned sales volume per country per category for the plan period by about 30-50% in the
v_plan_edit view on behalf of two managers. You can edit data through the view in DBeaver using a
virtual key (it must contain all fields except salesamt).
Run the function remove_lock to mark Q12014 as not in use. Run this function as Kirill and then as
Sophie. Now the v_plan_edit view will return no records.
Rules for updating the plan_status table are listed below:
Column |Description |Rules||
quarterid |Key of planning quarter |No changes||
sountry |Country of a shop which orders goods |No changes||
status |Plan data slice status |L||
modifieddatetime |Time when the record was changed or created |Value of current_timestamp||
author |User that changed the record |Value of current_user||
Tables used
Plan_status table should be updated. Country_managers stores information about users permissions regarding plan sales to different countries.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!