SQL Query Question:
I have a database with the tables below, data has also been aded into these tables,
I have 2 tasks:
1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new column consistent with the present contents of the sample database.
-
2. Use a single DELETE statement to remove from a relational table APPLIES all applications submitted by the applicants who do not have any skills. DELETE statement must be correct for any contents of the sample database.
Any help would be awesome thanks guys
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
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);
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
1. ALTER TABLE POSITIONS ADD COLUMN skills NUMBER;
ALTER TABLE POSITIONS ADD CONSTRAINT skills_check CHECK skills <= 9;
UPDATE POSITIONS SET skills = 0 WHERE skills IS NULL;
2. DELETE FROM APPLIES WHERE APPLIES.anumber = POSITIONS.anumber AND POSITIONS.skills = 0;
SQL Query Question: I have a database with the tables below, data has also been aded...
Using SQL statements in MySQL (1) Find the position number, title, employer and salary of positions that have been applied by the most amounts of applicants. (2) Find the applicant number, full name of applicants that possessed all skills needed by a position 00000005. Note that an applicant possessed all skills needed by a position means all skills (sname) needed are possessed by the applicant, and the skill levels (skilllevel) that needed less or equals to the correspondent skill levels...
I am trying to delete these tables from my data base and I keep getting: "mysql> DROP TABLE Courses; ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails" I am using the command DROP TABLE Courses; Below is my sql file use sdev300; // Create a student table CREATE TABLE Students ( PSUsername varchar(30) primary key, FirstName varchar(30), LastName varchar(30), EMail varchar(60) ); CREATE TABLE Courses( CourseID int primary key, CourseDisc varchar(4), CourseNum varchar(4),...
Database concepts Find the names and ids of the students who have taken at most one course in the Spring 2010 semester. Notice, at most one means one or zero. So, the answer should include students who did not take any course during that semester The data: create table classroom (building varchar(15), room_number varchar(7), capacity numeric(4,0), primary key (building, room_number) ); create table department (dept_name varchar(20), building varchar(15), budget numeric(12,2) check (budget > 0), primary key (dept_name) ); create...
database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE Department ( DECIMAL(5) VARCHAR(30) CHAR(5) DATE NOT NULL NOT NULL NOT NULL * Department number /*Department name * Department manager number */ /Manager start date DNumber DName Manager MSDate CONSTRAINT Department_PK PRIMARY KEY(DNumber) CONSTRAINT Department_CK UNIQUE(DName) CREATE TABLE DeptLocation DECIMAL(5) VARCHAR(50) NOT NULL NOT NULL DNumber * Department number */ * Department location */ Address CONSTRAINT DeptLocation_PK PRIMARY KEY(DNumber, Address) CONSTRAINT...
I need help with the following SQL query for a company database (script given below). The name of the Department. The number of employees working in that department. The number of different projects controlled by this department. The name of the project controlled by this department that has the maximum number of employees of the company working on it. The number of the above project. The cumulative sum of the number of employees of the company working on the projects...
This is database system concept. 1.Find the ids of instructors who are also students using a set operation. Assume that a person is identified by her or his id. So, if the same id appears in both instructor and student, then that person is both an instructor and a student. Remember: set operation means union, intersect or set difference. 2.Find the ids of instructors who are also students using the set membership operator. 3.Find the ids of instructors who are...
Write an SQL query to return the users who posted the most number of jokes on 1/1/2019. Database: create table User( userid varchar(30) not null, password varchar(30), firstname varchar(30), lastname varchar(50), email varchar(50), gender char(1), age integer, banned boolean, primary key(userid), unique(email)); create table MyFriends( userid varchar(30), friendid varchar(30), primary key(userid,friendid), foreign key(userid) references User, foreign key(friendid) references User(userid)); Create table Jokes( Jokeid integer, title varchar(100), description varchar(255), authorid varchar(30) not null, primary key(jokeid), posttime Datetime, foreign key(authorid) references User(userid));...
Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...
Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...
Help In Database: Next comes the data entry: Make up data for your database, or find real data. You can enter the data with INSERT statements, but it is much easier to use PhpAdmin. It has a form where you can type the data directly. Alternatively, you can use PhpAdmin to import CSV data (comma-separated values), which you can export from Excel. Include at least 3 rows in each of the entity relations, and as many rows as you need...