Question

In: Computer Science

This is the database CREATE TABLE AIRCRAFT ( AC_NUMBER varchar(5) primary key, MOD_CODE varchar(10), AC_TTAF double,...

This is the database


CREATE TABLE AIRCRAFT (
AC_NUMBER varchar(5) primary key,
MOD_CODE varchar(10),
AC_TTAF double,
AC_TTEL double,
AC_TTER double
);

INSERT INTO AIRCRAFT VALUES('1484P','PA23-250',1833.1,1833.1,101.8);
INSERT INTO AIRCRAFT VALUES('2289L','DC-90A',4243.8,768.9,1123.4);
INSERT INTO AIRCRAFT VALUES('2778V','MA23-350',7992.9,1513.1,789.5);
INSERT INTO AIRCRAFT VALUES('4278Y','PA31-950',2147.3,622.1,243.2);

/* -- */

CREATE TABLE CHARTER (
CHAR_TRIP int primary key,
CHAR_DATE date,
AC_NUMBER varchar(5),
CHAR_DESTINATION varchar(3),
CHAR_DISTANCE double,
CHAR_HOURS_FLOWN double,
CHAR_HOURS_WAIT double,
CHAR_TOT_CHG double,
CHAR_OIL_QTS int,
CUS_CODE int,
foreign key (AC_NUMBER) references AIRCRAFT(AC_NUMBER)
);

INSERT INTO CHARTER VALUES(10001,'2008-02-05','2289L','ATL',936,5.1,2.2,354.1,1,10011);
INSERT INTO CHARTER VALUES(10002,'2008-02-05','2778V','BNA',320,1.6,0,72.6,0,10016);
INSERT INTO CHARTER VALUES(10003,'2008-02-05','4278Y','GNV',1574,7.8,0,339.8,2,10014);
INSERT INTO CHARTER VALUES(10004,'2008-02-06','1484P','STL',472,2.9,4.9,97.2,1,10019);
INSERT INTO CHARTER VALUES(10005,'2008-02-06','2289L','ATL',1023,5.7,3.5,397.7,2,10011);
INSERT INTO CHARTER VALUES(10006,'2008-02-06','4278Y','STL',472,2.6,5.2,117.1,0,10017);
INSERT INTO CHARTER VALUES(10007,'2008-02-06','2778V','GNV',1574,7.9,0,348.4,2,10012);
INSERT INTO CHARTER VALUES(10008,'2008-02-07','1484P','TYS',644,4.1,0,140.6,1,10014);
INSERT INTO CHARTER VALUES(10009,'2008-02-07','2289L','GNV',1574,6.6,23.4,459.9,0,10017);
INSERT INTO CHARTER VALUES(10010,'2008-02-07','4278Y','ATL',998,6.2,3.2,279.7,0,10016);
INSERT INTO CHARTER VALUES(10011,'2008-02-07','1484P','BNA',352,1.9,5.3,66.4,1,10012);
INSERT INTO CHARTER VALUES(10012,'2008-02-08','2778V','MOB',884,4.8,4.2,215.1,0,10010);
INSERT INTO CHARTER VALUES(10013,'2008-02-08','4278Y','TYS',644,3.9,4.5,174.3,1,10011);
INSERT INTO CHARTER VALUES(10014,'2008-02-09','4278Y','ATL',936,6.1,2.1,302.6,0,10017);
INSERT INTO CHARTER VALUES(10015,'2008-02-09','2289L','GNV',1645,6.7,0,459.5,2,10016);
INSERT INTO CHARTER VALUES(10016,'2008-02-09','2778V','MQY',312,1.5,0,67.2,0,10011);
INSERT INTO CHARTER VALUES(10017,'2008-02-10','1484P','STL',508,3.1,0,105.5,0,10014);
INSERT INTO CHARTER VALUES(10018,'2008-02-10','4278Y','TYS',644,3.8,4.5,167.4,0,10017);

/* -- */

CREATE TABLE CREW (
CHAR_TRIP int,
EMP_NUM int,
CREW_JOB varchar(20),
primary key (CHAR_TRIP, EMP_NUM)
);

INSERT INTO CREW VALUES(10001,104,'Pilot');
INSERT INTO CREW VALUES(10002,101,'Pilot');
INSERT INTO CREW VALUES(10003,105,'Pilot');
INSERT INTO CREW VALUES(10003,109,'Copilot');
INSERT INTO CREW VALUES(10004,106,'Pilot');
INSERT INTO CREW VALUES(10005,101,'Pilot');
INSERT INTO CREW VALUES(10006,109,'Pilot');
INSERT INTO CREW VALUES(10007,104,'Pilot');
INSERT INTO CREW VALUES(10007,105,'Copilot');
INSERT INTO CREW VALUES(10008,106,'Pilot');
INSERT INTO CREW VALUES(10009,105,'Pilot');
INSERT INTO CREW VALUES(10010,108,'Pilot');
INSERT INTO CREW VALUES(10011,101,'Pilot');
INSERT INTO CREW VALUES(10011,104,'Copilot');
INSERT INTO CREW VALUES(10012,101,'Pilot');
INSERT INTO CREW VALUES(10013,105,'Pilot');
INSERT INTO CREW VALUES(10014,106,'Pilot');
INSERT INTO CREW VALUES(10015,101,'Copilot');
INSERT INTO CREW VALUES(10015,104,'Pilot');
INSERT INTO CREW VALUES(10016,105,'Copilot');
INSERT INTO CREW VALUES(10016,109,'Pilot');
INSERT INTO CREW VALUES(10017,101,'Pilot');
INSERT INTO CREW VALUES(10018,104,'Copilot');
INSERT INTO CREW VALUES(10018,105,'Pilot');

/* -- */

CREATE TABLE AC_CUSTOMER (
CUS_CODE int primary key,
CUS_LNAME varchar(15),
CUS_FNAME varchar(15),
CUS_INITIAL varchar(1),
CUS_AREACODE varchar(3),
CUS_PHONE varchar(8),
CUS_BALANCE double
);

INSERT INTO AC_CUSTOMER VALUES(10010,'Ramas','Alfred','A','615','844-2573',0);
INSERT INTO AC_CUSTOMER VALUES(10011,'Dunne','Leona','K','713','894-1238',0);
INSERT INTO AC_CUSTOMER VALUES(10012,'Smith','Kathy','W','615','894-2285',896.53);
INSERT INTO AC_CUSTOMER VALUES(10013,'Olowski','Paul','F','615','894-2180',1285.18);
INSERT INTO AC_CUSTOMER VALUES(10014,'Orlando','Myron',NULL,'615','222-1672',673.21);
INSERT INTO AC_CUSTOMER VALUES(10015,'O''Brian','Amy','B','713','442-3381',1014.55);
INSERT INTO AC_CUSTOMER VALUES(10016,'Brown','James','G','615','297-1228',0);
INSERT INTO AC_CUSTOMER VALUES(10017,'Williams','George','','615','290-2556',0);
INSERT INTO AC_CUSTOMER VALUES(10018,'Farriss','Anne','G','713','382-7185',0);
INSERT INTO AC_CUSTOMER VALUES(10019,'Smith','Olette','K','615','297-3809',453.9);

/* -- */

CREATE TABLE EARNEDRATING (
EMP_NUM int,
RTG_CODE varchar(5),
EARNRTG_DATE date,
primary key (emp_num, rtg_code)
);
INSERT INTO EARNEDRATING VALUES(101,'CFI','1998-02-18');
INSERT INTO EARNEDRATING VALUES(101,'CFII','2005-12-15');
INSERT INTO EARNEDRATING VALUES(101,'INSTR','1993-11-08');
INSERT INTO EARNEDRATING VALUES(101,'MEL','1994-06-23');
INSERT INTO EARNEDRATING VALUES(101,'SEL','1993-04-21');
INSERT INTO EARNEDRATING VALUES(104,'INSTR','1996-07-15');
INSERT INTO EARNEDRATING VALUES(104,'MEL','1997-01-09');
INSERT INTO EARNEDRATING VALUES(104,'SEL','1995-03-12');
INSERT INTO EARNEDRATING VALUES(105,'CFI','1997-11-18');
INSERT INTO EARNEDRATING VALUES(105,'INSTR','1995-04-17');
INSERT INTO EARNEDRATING VALUES(105,'MEL','1995-08-12');
INSERT INTO EARNEDRATING VALUES(105,'SEL','1994-09-23');
INSERT INTO EARNEDRATING VALUES(106,'INSTR','1995-12-20');
INSERT INTO EARNEDRATING VALUES(106,'MEL','1996-04-02');
INSERT INTO EARNEDRATING VALUES(106,'SEL','1994-03-10');
INSERT INTO EARNEDRATING VALUES(109,'CFI','1998-11-05');
INSERT INTO EARNEDRATING VALUES(109,'CFII','2003-06-21');
INSERT INTO EARNEDRATING VALUES(109,'INSTR','1996-07-23');
INSERT INTO EARNEDRATING VALUES(109,'MEL','1997-03-15');
INSERT INTO EARNEDRATING VALUES(109,'SEL','1996-02-05');
INSERT INTO EARNEDRATING VALUES(109,'SES','1996-05-12');

/* -- */

CREATE TABLE EMPLOYEE (
EMP_NUM int primary key,
EMP_TITLE varchar(4),
EMP_LNAME varchar(15),
EMP_FNAME varchar(15),
EMP_INITIAL varchar(1),
EMP_DOB date,
EMP_HIRE_DATE date
);
INSERT INTO EMPLOYEE VALUES(100,'Mr.','Kolmycz','George','D','1942-06-15','1987-03-15');
INSERT INTO EMPLOYEE VALUES(101,'Ms.','Lewis','Rhonda','G','1965-03-19','1988-04-25');
INSERT INTO EMPLOYEE VALUES(102,'Mr.','VanDam','Rhett','','1958-11-14','1992-12-20');
INSERT INTO EMPLOYEE VALUES(103,'Ms.','Jones','Anne','M','1974-10-16','2005-08-28');
INSERT INTO EMPLOYEE VALUES(104,'Mr.','Lange','John','P','1971-11-08','1996-10-20');
INSERT INTO EMPLOYEE VALUES(105,'Mr.','Williams','Robert','D','1975-03-14','2006-01-08');
INSERT INTO EMPLOYEE VALUES(106,'Mrs.','Duzak','Jeanine','K','1968-02-12','1991-01-05');
INSERT INTO EMPLOYEE VALUES(107,'Mr.','Diante','Jorge','D','1974-08-21','1996-07-02');
INSERT INTO EMPLOYEE VALUES(108,'Mr.','Wiesenbach','Paul','R','1966-02-14','1994-11-18');
INSERT INTO EMPLOYEE VALUES(109,'Ms.','Travis','Elizabeth','K','1961-06-18','1991-04-14');
INSERT INTO EMPLOYEE VALUES(110,'Mrs.','Genkazi','Leighla','W','1970-05-19','1992-12-01');

/* -- */

CREATE TABLE MODEL (
MOD_CODE varchar(10) primary key,
MOD_MANUFACTURER varchar(15),
MOD_NAME varchar(20),
MOD_SEATS double,
MOD_CHG_MILE double
);
INSERT INTO MODEL VALUES('DC-90A','Beechcraft','KingAir',8,2.67);
INSERT INTO MODEL VALUES('MA23-250','Piper','Aztec',6,1.92);
INSERT INTO MODEL VALUES('PA31-950','Piper','Navajo Chieftain',10,2.34);

/* -- */


CREATE TABLE PILOT (
EMP_NUM int primary key,
PIL_LICENSE varchar(25),
PIL_RATINGS varchar(25),
PIL_MED_TYPE varchar(1),
PIL_MED_DATE date,
PIL_PT135_DATE date
);
INSERT INTO PILOT VALUES(101,'ATP','SEL/MEL/Instr/CFII','1','2008-04-12','2007-05-16');
INSERT INTO PILOT VALUES(104,'ATP','SEL/MEL/Instr','1','2007-06-10','2008-03-23');
INSERT INTO PILOT VALUES(105,'COM','SEL/MEL/Instr/CFI','2','2008-02-25','2008-02-12');
INSERT INTO PILOT VALUES(106,'COM','SEL/MEL/Instr','2','2008-04-02','2007-12-24');
INSERT INTO PILOT VALUES(109,'COM','SEL/MEL/SES/Instr/CFII','1','2008-04-14','2008-04-21');

/* -- */

CREATE TABLE RATING (
RTG_CODE varchar(5) primary key,
RTG_NAME varchar(50)
);
INSERT INTO RATING VALUES('CFI','Certified Flight Instructor');
INSERT INTO RATING VALUES('CFII','Certified Flight Instructor, Instrument');
INSERT INTO RATING VALUES('INSTR','Instrument');
INSERT INTO RATING VALUES('MEL','Multiengine Land');
INSERT INTO RATING VALUES('SEL','Single Engine, Land');
INSERT INTO RATING VALUES('SES','Single Engine, Sea');

Answer the following questions based on the above database:

     

  1. (4 Points) Create a view named “ATL_CHARTERS_V” that includes the following “For each charter of aircraft to Atlanta (STL), print the charter date, charter hours flown, and the corresponding customer last name, first name, area code, and phone number”. Your answer should include both the SQL statement for view creating along with the contents of the view (you get the contents of the view by select * from ATL-CHARTERS_V).

  1. (4 Points) Modify the MODEL table to add the following attribute: (Note: use ALTER TABLE and UPDATE commands for this question.)

Attribute name

Attribute Description

Attribute type

MOD_LIFT_ WEIGHT

Amount of weight each model can lift

Numeric

Once the attribute has been added, update the values of all rows as per following values:

Attribute values for MOD_LIFT_WEIGHT

10,000 for Mod_code = DC-90A

5,000 for Mod_code = MA23-250

20,000 for Mod_code = PA31-950

  1. (4 Points) Create a trigger named trg_charter_hours that will automatically update the AIRCRAFT table after a new CHARTER row is added. Use the CHARTER table’s CHAR_HOURS_FLOWN to update the AIRCRAFT table’s AC_TTAF, AC_TTEL, and AC_TTER values.

The meaning for the AIRCRAFT table columns are as follows:

AC_TTAF: Total time on the air frame

AC_TTEL: Total time on the left engine (Also used to record single engine hours) AC_TTER: Total time on the right engine.

So in the trigger, you need to increase all of them with value of CHAR_HOURS_FLOWN

  1. (4 Points) Create a trigger named trg_cust_balance that will automatically update the AC_CUSTOMER table’s CUS_BALANCE before a new CHARTER row is added. Use the CHARTER table’s CHAR_TOT_CHG as the update source (Assume that all charter charges are charged to the customer balance.) In addition to the CHAR_TOT_CHG, add $25 for every quart of oil

used on the charter.

  1. (4 Points) Create a stored procedure to update model charge per mile attribute. Procedure takes the model number as a parameter. The procedure increases the charge for this model by 25%.
  1. (4 Points) Create a stored procedure that will take an Employee number and percentage, then update the corresponding employee’s hourly salary by the input percentage (increase the hourly salary, so you are giving the employee a raise).

Hint: Alter Employee table to add the hourly_salary field, update it with a value of 30 for all rows in the table, before creating the procedure.

Solutions

Expert Solution

Create a view named “ATL_CHARTERS_V”

create view ATL_CHARTERS_V AS
select c.CHAR_DATE, c.CHAR_HOURS_FLOWN,
a.CUS_LNAME ,a.CUS_FNAME ,a.CUS_AREACODE ,a.CUS_PHONE
from CHARTER AS c, AC_CUSTOMER AS a
where c.CUS_CODE=a.CUS_CODE;

contents of the view

select * from ATL_CHARTERS_V;

ALTER table command to add new column to table MODEL

Alter table MODEL ADD MOD_LIFT_WEIGHT Numeric;

UPDATE command to update values in table MODEL

update MODEL SET MOD_LIFT_WEIGHT='10,000' WHERE MOD_CODE ='DC-90A';

update MODEL SET MOD_LIFT_WEIGHT='5,000' WHERE MOD_CODE ='MA23-250';

update MODEL SET MOD_LIFT_WEIGHT='20,000' WHERE MOD_CODE ='PA31-950';

select * from MODEL;

Triggers are associated with tables and are called before or after a data row is inserted, updated or deleted.

A trigger named trg_char_hours that will automatically update the AIRCRAFT table when a new CHARTER row is added.

CREATE trg_charter_hours

AFTER INSERT ON CHARTER

FOR EACH ROW

BEGIN

UPDATE AIRCRAFT

SET AC_TTAF = AC_TTAF + :NEW.CHAR_HOURS_FLOWN,

AC_TTEL = AC_TTEL + :NEW.CHAR_HOURS_FLOWN,

AC_TTER = AC_TTER + :NEW.CHAR_HOURS_FLOWN

WHERE AIRCRAFT.AC_NUMBER = :NEW.AC_NUMBER;

END;

Create a trigger named trg_cust_balance that will automatically update the AC_CUSTOMER table’s CUS_BALANCE before a new CHARTER row is added.

CREATE TRIGGER trg_cust_balance

AFTER INSERT ON CHARTER

FOR EACH ROW

BEGIN

UPDATE CUSTOMER

SET CUS_BALANCE = CUS_BALANCE + :NEW.CHAR_TOT_CHG

WHERE CUSTOMER.CUS_CODE = :NEW.CUS_CODE;

END;

Note- As per the policy answering only 4 parts.

If this answer is helpful give it a thumbs up. Thank You


Related Solutions

create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key,...
create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); write an SQL query that lists all those nodes that have edges with a destination node that has color 'red'.
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table...
Consider the following table definitions create table node( node_id integer primary key, node_color varchar(10)); create table edge( edge_id integer primary key, origin_id integer, destination_id integer, foreign key (origin_id) references node(node_id), foreign key (destination_id) references node(node_id)); What is the result of the following query? select node_id, node_color, destination_id from node, edge; An inner join of the tables node and edge that lists origin node_id and node_color together with the node_id of the destination node for all those nodes that have outgoing...
CREATE TABLE Branch ( branchNo VARCHAR(4), address VARCHAR(50), city VARCHAR(30), state VARCHAR(2), phone VARCHAR(20), PRIMARY KEY...
CREATE TABLE Branch ( branchNo VARCHAR(4), address VARCHAR(50), city VARCHAR(30), state VARCHAR(2), phone VARCHAR(20), PRIMARY KEY (branchNo)); INSERT INTO Branch VALUES('B001','366 Tiger Ln','Los Angeles','CA','213-539-8600'); INSERT INTO Branch VALUES('B002','18 Harrison Rd','New Haven','CT','203-444-1818'); INSERT INTO Branch VALUES('B003','55 Waydell St','Essex','NJ','201-700-7007'); INSERT INTO Branch VALUES('B004','22 Canal St','New York','NY','212-055-9000'); INSERT INTO Branch VALUES('B005','1725 Roosevelt Ave','Queens','NY','718-963-8100'); INSERT INTO Branch VALUES('B006','1471 Jerrold Ave','Philadelphia','PA','267-222-5252'); CREATE TABLE Staff ( staffNo VARCHAR(4), fName VARCHAR(20), lName VARCHAR(20), position VARCHAR(20), sex VARCHAR(1), age INTEGER, salary NUMBER(8,2), phone VARCHAR(20), address VARCHAR(50), city VARCHAR(20),...
Consider the following SQL DDL statements: CREATE TABLE DEPT ( did INTEGER, dname VARCHAR(20), PRIMARY KEY(did));...
Consider the following SQL DDL statements: CREATE TABLE DEPT ( did INTEGER, dname VARCHAR(20), PRIMARY KEY(did)); CREATE TABLE EMP( eid INTEGER, name VARCHAR(20), did INTEGER, PRIMARY KEY(eid), FOREIGN KEY(did) REFERENCES DEPT); In the database created by above statements, which of the following operations may cause violation of referential integrity constraints? Question 1 options: UPDATE on DEPT INSERT into DEPT DELETE on EMP Both DELETE on EMP and INSERT into DEPT
Create table, create primary and foreign key constraints. Create index on the table to satisfy a...
Create table, create primary and foreign key constraints. Create index on the table to satisfy a query with aggregate functions.
Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255)...
Create a table book_store with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_genre VARCHAR(255) NOT NULL, Status VARCHAR(255) NOT NULL, PRIMARY KEY (Book_id) Create a table book with columns Book_id VARCHAR(255) NOT NULL, Book_Name VARCHAR(255) NOT NULL, Book_release integer, Book_price integer , Publisher Varchar(10), Book_genre VARCHAR(255) NOT NULL, PRIMARY KEY (Book_id) CREATE TABLE price_logs with columns id INT(11) NOT NULL AUTO_INCREMENT, Book_id VARCHAR(255) NOT NULL, Old_Book_price DOUBLE NOT NULL, New_Book_price DOUBLE NOT NULL, updated_at TIMESTAMP NOT NULL DEFAULT...
Design a database/mysql that has 3 tables: TABLE 1 student: StudID (int), LastName (varchar), FirstName (varchar),...
Design a database/mysql that has 3 tables: TABLE 1 student: StudID (int), LastName (varchar), FirstName (varchar), MiddleName(varchar) TABLE 2 Course: StudID, CourseID TABLE 3 study course: CourseID(int), CourseTitle(varchar), Units(int), PreqCourse(varchar) ** Insert at least 5 records. ** Use the "select" command to view the content of the tables. ** POST THE SCREENSHOT
CREATE TABLE youtubevideos( url VARCHAR(150), title VARCHAR(50), description VARCHAR(200), comid INTEGER NOT NULL, postuserVARCHAR(50) NOT NULL,...
CREATE TABLE youtubevideos( url VARCHAR(150), title VARCHAR(50), description VARCHAR(200), comid INTEGER NOT NULL, postuserVARCHAR(50) NOT NULL, postdate DATE, PRIMARY KEY (email), FOREIGN KEY (comid) REFERENCES Comedians(comid), FOREIGN KEY (postuser) REFERENCES Users(email)); CREATE TABLE Users( email VARCHAR(50), password VARCHAR(50), firstname VARCHAR(50), lastname VARCHAR(50), gender CHAR(1), age INTEGER, PRIMARY KEY (email)); CREATE TABLE Comedians( comid INTEGER, firstname VARCHAR(50), lastname VARCHAR(50), birthday DATE, VARCHAR(50), PRIMARY KEY(comid)); CREATE TABLE Reviews( reviewid INTEGER NOT NULL AUTO_INCREMENT, remark VARCHAR(100), rating CHAR(1), //P.F.G.E author VARCHAR(50) NOT NULL,...
what is super key,  candidate key, and primary key, and foreign key in terms of database? and...
what is super key,  candidate key, and primary key, and foreign key in terms of database? and plz provide some examples, thanks.
Create a Database in POSTGRESQL using the following table names and attributes: users: userid (int, primary...
Create a Database in POSTGRESQL using the following table names and attributes: users: userid (int, primary key), name (text) movies: movieid (integer, primary key), title (text) taginfo: tagid (int, primary key), content (text) genres: genreid (integer, primary key), name (text) ratings: userid (int, foreign key), movieid (int, foreign key), rating (numeric), timestamp (bigint, seconds since midnight Coordinated Universal Time (UTC) of January 1, 1970) tags: userid (int, foreign key), movieid (int, foreign key), tagid (int, foreign key), timestamp (bigint, seconds...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT