Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SQL Query related question: Ok so I have a database called 'ak898', and a user called 'emp' my task is to grant a privilege to

SQL Query related question:

Ok so I have a database called 'ak898', and a user called 'emp' my task is to grant a privilege to read information about all positions (all columns from POSITIONS table) such that each position needs only one skill to a user 'emp' The privilege must be granted such that a user emp is not allowed to grant the same privilege to another user. The database consists of the following tables:

-

Any help would be awesome thank you!

-

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

CREATE TABLE SKILL( sname VARCHAR(30) NOT NULL, /* Skill name */ CONSTRAINT SKILL_pkey PRIMARY KEY ( sname ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE SREQUIRED( sname VARCHAR(30) NOT NULL, /* Skill name */ requires VARCHAR(30) NOT NULL, /* Skill required */ slevel DECIMAL(2) NOT NULL, /* Level required */ CONSTRAINT SREQUIRED_pkey PRIMARY KEY ( sname, requires ), CONSTRAINT SREQUIRED_fkey1 FOREIGN KEY ( sname) REFERENCES SKILL( sname ), CONSTRAINT SREQUIRED_fkey2 FOREIGN KEY ( requires ) REFERENCES SKILL( sname ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* Relational tables implementing classes of objects */ /* */ CREATE TABLE APPLICANT( /* Applicants */ anumber DECIMAL(6) NOT NULL, /* Applicant number */ fname VARCHAR(20) NOT NULL, /* First name */ lname VARCHAR(30) NOT NULL, /* Last name */ dob DATE NOT NULL, /* Date of birth */ city VARCHAR(30) NOT NULL, /* City */ state VARCHAR(20) NOT NULL, /* State */ phone DECIMAL(10) NOT NULL, /* Phone number */ fax DECIMAL(10) , /* Fax number */ email VARCHAR(50) , /* E-mail address */ CONSTRAINT APPLICANT_pkey PRIMARY KEY ( anumber ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE EMPLOYER( /* Employers */ ename VARCHAR(100) NOT NULL, /* Employer name */ city VARCHAR(30) NOT NULL, /* City */ state VARCHAR(20) NOT NULL, /* State */ phone DECIMAL(10) NOT NULL, /* Phone number */ fax DECIMAL(10) , /* Fax number */ email VARCHAR(50) , /* E-mail address */ web VARCHAR(50) , /* Web site address */ CONSTRAINT EMPLOYER_pkey PRIMARY KEY ( ename ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE POSITIONS( /* Advertised positions */ pnumber DECIMAL(8) NOT NULL, /* Position number */ title VARCHAR(30) NOT NULL, /* Position title */ salary DECIMAL(9,2) NOT NULL, /* Salary */ extras VARCHAR(50) , /* Extras */ bonus DECIMAL(9,2) , /* End of year bonus */ specification VARCHAR(2000) NOT NULL, /* Specification */ ename VARCHAR(100) NOT NULL, /* Employer name */ CONSTRAINT POSITION_pkey PRIMARY KEY ( pnumber ), CONSTRAINT POSITION_fkey FOREIGN KEY ( ename) REFERENCES EMPLOYER( ename ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ CREATE TABLE EMPLBY( /* Former employers */ anumber DECIMAL(6) NOT NULL, /* Applicant number */ ename VARCHAR(100) NOT NULL, /* Employer name */ fromdate DATE NOT NULL, /* Employed from */ todate DATE , /* Employed to */ CONSTRAINT EMPLBY_pkey PRIMARY KEY ( anumber, ename, fromdate ), CONSTRAINT EMPLBY_fkey1 FOREIGN KEY ( anumber ) REFERENCES APPLICANT( anumber ), CONSTRAINT EMPLBY_fkey2 FOREIGN KEY ( ename ) REFERENCES EMPLOYER( ename ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ /* Relational tables implementing associations */ /* */ CREATE TABLE SPOSSESSED( anumber DECIMAL(6) NOT NULL, /* Applicant number */ sname VARCHAR(30) NOT NULL, /* Skill name */ slevel DECIMAL(2) NOT NULL, /* Skill level */ CONSTRAINT SPOSSESSED_pkey PRIMARY KEY ( anumber, sname ), CONSTRAINT SPOSSESSED_fkey1 FOREIGN KEY ( anumber ) REFERENCES APPLICANT ( anumber ) ON DELETE CASCADE, CONSTRAINT SPOSSESSED_fkey2 FOREIGN KEY ( sname ) REFERENCES SKILL ( sname ), CONSTRAINT SPOSSESSED_check1 CHECK ( slevel IN ( 1,2,3,4,5,6,7,8,9,10 ) ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

CREATE TABLE SNEEDED( pnumber DECIMAL(8) NOT NULL, /* Position number */ sname VARCHAR(30) NOT NULL, /* Skill name */ slevel DECIMAL(2) NOT NULL, /* Skill level */ CONSTRAINT SNEEDED_pkey PRIMARY KEY ( pnumber, sname ), CONSTRAINT SNEEDED_fkey1 FOREIGN KEY ( pnumber ) REFERENCES POSITIONS ( pnumber ) ON DELETE CASCADE, CONSTRAINT SNEEDED_fkey2 FOREIGN KEY ( sname ) REFERENCES SKILL ( sname ), CONSTRAINT SNEEDED_check1 CHECK ( slevel IN ( 1,2,3,4,5,6,7,8,9,10 ) ) );

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

CREATE TABLE APPLIES( anumber DECIMAL(6) NOT NULL, /* Applicant number */ pnumber DECIMAL(8) NOT NULL, /* Position number */ appdate DATE NOT NULL, /* Application date */ CONSTRAINT APPLIES_pkey PRIMARY KEY ( anumber, pnumber ), CONSTRAINT APPLIES_fkey1 FOREIGN KEY ( anumber ) REFERENCES APPLICANT ( anumber ) ON DELETE CASCADE, CONSTRAINT APPLIES_fkey2 FOREIGN KEY ( pnumber ) REFERENCES POSITIONS ( pnumber ) ON DELETE CASCADE);

/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

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

More Books

Students also viewed these Databases questions