Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 planstatus
quarterid varchar NOT NULL,
status varchar NOT NULL,
modifieddatetime timestamp DEFAULT CURRENTTIMESTAMP NOT NULL,
author varchar DEFAULT CURRENTUSER NOT NULL,
country varchar NOT NULL,
CONSTRAINT planstatuspk PRIMARY KEY quarterid country
;
CREATE TABLE countrymanagers
username varchar NOT NULL,
country varchar NOT NULL,
CONSTRAINT countrymanagerspk PRIMARY KEY username country
;
Write two functions in python:
setlockyear quarter, user, pwd which will change status from R to L for records in
planstatus, that are associated with the target quarter and year, and connected to the current
user in the countrymanagers configuration table. To obtain the name of the current user, use
currentuser. Also write a timestamp of modification to the modifieddatetime field.
removelockyear quarter, user, pwd function, that will change the planning data status from
L to R associated with the current user through the countrymanagers table. Also update the
modifieddatetime field.
Execute the setlock function to lock the plan data for the st quarter of on behalf of Kirill user,
and then Sophie. If everything is done correctly, data will appear in the vplanedit view if
connected as Kirill or Sophie.
Increase the planned sales volume per country per category for the plan period by about in the
vplanedit 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 removelock to mark Q as not in use. Run this function as Kirill and then as
Sophie. Now the vplanedit view will return no records.
Rules for updating the planstatus 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 currenttimestamp
author User that changed the record Value of currentuser
Tables used
Planstatus table should be updated. Countrymanagers stores information about users permissions regarding plan sales to different countries.
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