Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions

Question

What is the managerial capacity problem?

Answered: 1 week ago

Question

Prepare a short profile of Henry words worth Longfellow?

Answered: 1 week ago

Question

What is RAM as far as telecommunication is concerned?

Answered: 1 week ago

Question

Question 1: What is reproductive system? Question 2: What is Semen?

Answered: 1 week ago

Question

Describe the sources of long term financing.

Answered: 1 week ago