ddata 324 hw 2
.docx
keyboard_arrow_up
School
Washington State University *
*We aren’t endorsed by this school
Course
424
Subject
Computer Science
Date
Feb 20, 2024
Type
docx
Pages
5
Uploaded by Titanninja
CREATE TABLE Patient (
SSN VARCHAR
(
11
) NOT NULL PRIMARY KEY
,
name VARCHAR
(
50
) NOT NULL
,
age INT NOT NULL
,
phySSN VARCHAR
(
11
) NOT NULL
,
FOREIGN KEY (phySSN) REFERENCES Pri_physician(SSN)
);
CREATE TABLE Pri_physician (
SSN VARCHAR
(
11
) NOT NULL PRIMARY KEY
,
name VARCHAR
(
50
) NOT NULL
,
specialty VARCHAR
(
50
) NOT NULL
,
experience INT NOT NULL
,
FOREIGN KEY (SSN) REFERENCES Doctor(SSN)
);
CREATE TABLE Doctor (
SSN VARCHAR
(
11
) NOT NULL PRIMARY KEY
,
name VARCHAR
(
50
) NOT NULL
,
experience INT NOT NULL
,
presi VARCHAR
(
11
) NOT NULL
,
FOREIGN KEY (presi) REFERENCES Clinic(SSN)
);
CREATE TABLE Clinic (
SSN VARCHAR
(
11
) NOT NULL PRIMARY KEY
,
clinic_name VARCHAR
(
50
) NOT NULL
,
phone_num VARCHAR
(
15
) NOT NULL
,
address VARCHAR
(
100
) NOT NULL
);
CREATE TABLE Prescription (
date DATE NOT NULL
,
SSN VARCHAR
(
11
) NOT NULL
,
drug_name VARCHAR
(
50
) NOT NULL
,
PRIMARY KEY (
date
, SSN, drug_name),
FOREIGN KEY (SSN) REFERENCES Doctor(SSN),
FOREIGN KEY (drug_name) REFERENCES Drug(drug_name)
);
CREATE TABLE Pharmacy (
name VARCHAR
(
50
) NOT NULL PRIMARY KEY
,
phone_num VARCHAR
(
15
) NOT NULL
,
address VARCHAR
(
100
) NOT NULL
,
city VARCHAR
(
50
) NOT NULL
);
CREATE TABLE Sell (
name VARCHAR
(
50
) NOT NULL
,
drug_name VARCHAR
(
50
) NOT NULL
,
price FLOAT NOT NULL
,
PRIMARY KEY (
name
, drug_name),
FOREIGN KEY (
name
) REFERENCES Pharmacy(
name
),
FOREIGN KEY (drug_name) REFERENCES Drug(drug_name)
);
CREATE TABLE Drug (
drug_name VARCHAR
(
50
) NOT NULL PRIMARY KEY
,
formula VARCHAR
(
100
) NOT NULL
);
CREATE TABLE Online_pharmacy (
name VARCHAR
(
50
) NOT NULL PRIMARY KEY
,
WebURL VARCHAR
(
100
) NOT NULL
,
FOREIGN KEY (
name
) REFERENCES Pharmacy(
name
)
);
CREATE TABLE InStore_pharmacy (
name VARCHAR
(
50
) NOT NULL PRIMARY
KEY
,
FOREIGN KEY (
name
) REFERENCES Pharmacy(
name
)
);
CREATE TABLE DrugCompany (
company_id INT NOT NULL
,
name VARCHAR
(
100
),
phone_num CHAR
(
10
),
address VARCHAR
(
255
),
contract TEXT
,
supervisor VARCHAR
(
100
),
start_date DATE
,
end_date DATE
,
PRIMARY KEY (company_id),
UNIQUE (phone_num)
);
1.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
DROP TABLE IF EXISTS Worker;
CREATE TABLE Worker (
);
0
INSERT
);
WORKER_ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
FIRST NAME TEXT,
LAST NAME TEXT,
SALARY INTEGER (15),
JOINING DATE DATETIME,
DEPARTMENT CHAR (25)
INTO Worker
(WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING_DATE, DEPARTMENT) VALUES
'Arora', 100000, '14-02-20 09.00.00', 'HR'),
(001, 'Monika',
(002, 'Niharika',
'Verma' 80000, '14-06-11 09.00.00', 'Admin'),
'HR'),
'Admin'),
Admin'),
'Account'),
'Kumar', 75000, '14-01-20 09.00.00', 'Account')
DROP TABLE IF EXISTS Bonus;
CREATE TABLE Bonus (
);
(003, 'Vishal' 'Singhal', 300000, '14-02-20 09.00.00',
(004, 'Amitabh
'Singh', 500000, '14-02-20 09.00.00',
(005, 'Vivek' 'Bhati', 500000, '14-06-11 09.00.00'.
(006, 'Vipul', 'Diwan' 200000, '14-06-11 09.00.00',
(007, 'Satish'
(008, 'Geetika', 'Chauhan', 90000, '14-04-11 09.00.00', 'Admin');
WORKER_REF_ID INTEGER,
BONUS AMOUNT INTEGER(10),
BONUS_DATE DATETIME,
FOREIGN KEY (WORKER_REF_ID)
REFERENCES Worker (WORKER_ID)
ON DELETE…
arrow_forward
CREATE TABLE DONORS (donor_id INT NOT NULL,donor_name varchar(255) NOT NULL,donor_age int,PRIMARY KEY (donor_id ));CREATE TABLE DONATIONS(pledge_id INT NOT NULL,pledge_date varchar(255) NOT NULL,amount_pledged int,Is_paid int,donor_id int,PRIMARY KEY (pledge_id ),FOREIGN KEY (donor_id) REFERENCES DONORS(donor_id));
1. Populate every relation with three rows.
arrow_forward
The Car Maintenance team also wants to store the actual maintenance operations in the database. The team wants to start with a table to store CAR_ID (CHAR(5)), MAINTENANCE_TYPE_ID (CHAR(5)) and MAINTENANCE_DUE (DATE) date for the operation. Create a new table named MAINTENANCES. The PRIMARY_KEY should be the combination of the three fields. The CAR_ID and MAINTENACNE_TYPE_ID should be foreign keys to their original tables. Cascade update and cascade delete the foreign keys.
arrow_forward
drop table Parents_Children;drop table Persons;
create table Persons (name varchar(64) primary key,gender char(1) not null);
create table Parents_Children (parent varchar(64),child varchar(64),primary key (parent, child),foreign key (parent) references Persons(name),foreign key (child) references Persons(name));
insert into Persons (name, gender) values ('Ann', 'F');insert into Persons (name, gender) values ('Bob', 'M');insert into Persons (name, gender) values ('Cory', 'M');insert into Persons (name, gender) values ('Dave', 'M');insert into Persons (name, gender) values ('Emma', 'F');insert into Persons (name, gender) values ('Fred', 'M');insert into Persons (name, gender) values ('Gab', 'Q');insert into Persons (name, gender) values ('Hil', 'F');insert into Persons (name, gender) values ('Ian', 'M');
insert into Parents_Children (parent, child) values ('Ann', 'Bob');insert into Parents_Children (parent, child) values ('Ann', 'Cory');insert into Parents_Children (parent, child) values…
arrow_forward
Using the Winners table from Figure 12-2, write a parameter query that selects theActor and Actress fields for the year provided by the user.
arrow_forward
Considering Vaccination Database, write queries to:
Display the Subject CNIC, Name, Contact, Dose1 Center, and Dose2 Center as shown below:
CNIC
Name
Contact
Dose1 Center
Dose2 Center
22401-6645321-1
Nasir
3409991112
Lachi
Kohat 2
14301-6045321-5
Shahab
3409991112
kohat 3
Dara
The subjects who have been vaccinated different types in Dose1 and Dose2. For instance, subjects who were vaccinated ‘Sinovac’ in the first dose, while Pfizer in the second dose.How many Viles of each type have been consumed so far. How many subjects are vaccinated from expired viles. Suggest the name of Incharge for the best performance award based on the highest number of subjects vaccinated on a single day
arrow_forward
CREATE 3 tables as listed below in your own database. */ CREATE TABLE Customer (CustomerID VARCHAR(20) PRIMARY KEY, CustomerLName VARCHAR(30), CustomerFName VARCHAR(30), CustomerStatus VARCHAR(10)); CREATE TABLE SaleOrder (OrderID INT IDENTITY PRIMARY KEY, CustomerID VARCHAR(20) REFERENCES Customer(CustomerID), OrderDate DATE, OrderAmountBeforeTax INT);
CREATE TABLE SaleOrderDetail (OrderID INT REFERENCES SaleOrder(OrderID), ProductID INT, Quantity INT, UnitPrice INT, PRIMARY KEY (OrderID, ProductID)); /* Write a trigger to put the total sale order amount before tax (unit price * quantity for all items included in an order) in the OrderAmountBeforeTax column of SaleOrder. */
arrow_forward
Task 2:
The Car Maintenance team also wants to store the actual maintenance operations in the database. The team wants to start with a table to store CAR_ID (CHAR(5)), MAINTENANCE_TYPE_ID (CHAR(5)) and MAINTENANCE_DUE (DATE) date for the operation. Create a new table named MAINTENANCES. The PRIMARY_KEY should be the combination of the three fields. The CAR_ID and MAINTENANCE_TYPE_ID should be foreign keys to their original tables. Cascade update and cascade delete the foreign keys.
Create a new table to store maintenance operations
Test Query
DESCRIBE MAINTENANCES
Expected Results
Field
Type
Null
Key
Default
Extra
CAR_ID
char(5)
NO
PRI
NULL
MAINTENANCE_TYPE_ID
char(5)
NO
PRI
NULL
MAINTENANCE_DUE
date
NO
PRI
NULL
arrow_forward
Task 2:
The Car Maintenance team also wants to store the actual maintenance operations in the database. The team wants to start with a table to store CAR_ID (CHAR(5)), MAINTENANCE_TYPE_ID (CHAR(5)) and MAINTENANCE_DUE (DATE) date for the operation. Create a new table named MAINTENANCES. The PRIMARY_KEY should be the combination of the three fields. The CAR_ID and MAINTENACNE_TYPE_ID should be foreign keys to their original tables. Cascade update and cascade delete the foreign keys.
Answer in MYSQL please
arrow_forward
CREATE TABLE Users(
C_Id varchar(8) NOT NULL,
LastName Varchar(255) NOT NULL,
FirstName varchar(255) NOT NULL,
ema il varchar(255),
Phone int,
PRIMARY KÉY (C_Id)
CREATE TABLE Restaurants(
R_Id varchar(255) NOT NULL,
Rname varchar(255) NOT NULL,
Type varchar(255),
Raddress varchar(255),
Rphone int,
Remail varchar(255),
PRIMARY KEY(R_Id)
);
CREATE TABLE RDate(
T_num int NOT NULL,
Bdate DATE,
Rdate DATE,
T_start varchar(255),
E_start varchar(255),
PRIMARY KEY(T_num)
);
CREATE TABLE Book ingInfo(
C_Id varchar(8) NOT NULL,
R_Id int NOT NÚLL,
PRIMARY KEY(C_Id, R_Id),
FOREIGN KEY (C_Ià) REFERENCES Users(C Id),
FOREIGN KEY (R_Id) REFERENCES Restaurant(R_Id)
);
CREATE TABLE Rating(
R_Id varchar(255) NÓT NULL,
Rating Id varchar(255) NOT NULL,
Rate varchar(255) CHECK (Rate>11),
Comment LONG,
PRIMARY KEY(Rating Id),
FOREIGN KEY (R_Id) REFERENCES Restaurants(R_Id)
);
Create 1 procedure
Create 1 function
Create 1 database trigger |
arrow_forward
Create an ADD TRIGGER. Explain what the trigger does. Test and show the related results of this trigger.
Table 1:
CREATE TABLE BSR_PASSENGER
(PASSENGER_ID INT NOT NULL UNIQUE,
FULL_NAME VARCHAR(30),
COUNTRY VARCHAR(40),
CITY VARCHAR (40),
PRIMARY KEY (PASSENGER_ID));
Table 2:
CREATE TABLE BSR_FLIGHT
(FLIGHT_ID INT NOT NULL UNIQUE,
AIRLINE_NAME VARCHAR(50),
CREW_MEMBERS INT,
PRIMARY KEY (FLIGHT_ID));
Table 3:
CREATE TABLE BSR_BOOKING
(BOOKING_ID INT NOT NULL UNIQUE AUTO_INCREMENT,
PASSENGER_ID INT NOT NULL,
FLIGHT_ID INT NOT NULL,
COST DEC(6,3),
PRIMARY KEY (BOOKING_ID),
FOREIGN KEY (PASSENGER_ID) REFERENCES BSR_PASSENGER(PASSENGER_ID),
FOREIGN KEY (FLIGHT_ID) REFERENCES BSR_FLIGHT(FLIGHT_ID));
arrow_forward
Assistance with SQL statements
Previous code;
CREATE TABLE Lab4program_piershed ( code VARCHAR(5) PRIMARY KEY, name VARCHAR(20), tel VARCHAR(20));CREATE TABLE Lab4course_xxxx ( cid INT PRIMARY KEY, name VARCHAR(20), credits INT, mycode VARCHAR(5), FOREIGN KEY (mycode) REFERENCES Lab4program_xxxx(code));
1. Insert 3 records into your Lab4program_xxxx table. The code should be "CPS", "TECH", "MATH", or "BIO". Please copy/paste your SQL statements with the output message in the text that shows you successfully insert 3 records to your table.
2. Insert 4 records into your Lab4course_xxxx table with at least 2 different mycode. Please copy/paste your SQL statements with the output message in the text that shows you successfully insert 4 records to your table.
arrow_forward
You have the following tables:
APARTMENTS (ADDRESS, CITY, STATE, RENTER_ID, RENTER_LAST_NAME)
RENTERS (RENTER_ID, FIRST_NAME, LAST_NAME)
What is the primary key for the APARTMENTS table? (It may be a composite key involving 2 or more fields) What are the foreign keys, if any?
What is the primary key for the RENTERS table? What are the foreign keys, if any?
What field in RENTERS can be eliminated so that the RENTERS table is normalized?
arrow_forward
Using the Henry Books database, add the new title from Stephen King to the wrote table:
Book code = 3578
Author number = 6
Edition = 1
You will insert 2 snips for this question.
What construct did you use to add a row to the wrote table. Insert the snip of the construct used:
Insert the snip of the wrote table. Be sure the new row is displayed:
arrow_forward
Create a view vLab2_xxx in the class database listing the number of staff and the maximum and minimum salary for each branch city. Your view header names should be: (city, count, max_salary, min_salary), in ascending order of count.
arrow_forward
CREATE TABLE sales ( SalesNumber INT(10) AUTO_INCREMENT PRIMARY KEY, SalesDate DATE, SalesTotal DECIMAL(10,2));
CREATE TABLE products ( number INT(11) AUTO_INCREMENT PRIMARY KEY, prodid VARCHAR(20) UNIQUE, prodname VARCHAR(30), price DECIMAL(10,2), onhand INT(11), CONSTRAINT fk_salesdetails_products FOREIGN KEY (prodid) REFERENCES salesdetails(prodid) ON DELETE RESTRICT);
CREATE TABLE salesdetails ( number INT(10) AUTO_INCREMENT PRIMARY KEY, SalesNumber INT(10), prodid VARCHAR(20), price DECIMAL(7,2), qty INT(10), CONSTRAINT fk_salesdetails_sales FOREIGN KEY (SalesNumber) REFERENCES sales(SalesNumber) ON DELETE CASCADE, CONSTRAINT fk_salesdetails_products FOREIGN KEY (prodid) REFERENCES products(prodid) ON DELETE CASCADE);
Using the above SQL and the schema diagram, create an ER diagram detailing all the fields of the tables and the relationship amount the tables.
arrow_forward
4 and 5
arrow_forward
Create a new table named BOOK_TYPE in the finalexam database. The BOOK_TYPE table has two character columns: TYPE has a length of 3 characters and is the table’s primary key, and DESCRIPTION has a length of 20 characters.
arrow_forward
Modify the PILOT table to add the attribute shown in the following table, with a precision and scale of (8,2).
arrow_forward
MySQL
CREATE TABLE students ( id INT PRIMARY KEY, first_name VARCHAR(50), last_name VARCHAR(50), age INT, major VARCHAR(50), faculty VARCHAR(50));
CREATE TABLE location ( id INT PRIMARY KEY, name VARCHAR(50), rooms INT);
CREATE TABLE faculty ( id INT PRIMARY KEY, name VARCHAR(50), department_id INT);
4. Find the number of employees in each department who get no commission or have salary less than5000.5. Find the maximum salary of employees in each department that the employee was hired 15 yearsbefore now. *hint: user TIMESTAMPDIFF(<unit type>,<Date_value 1>,<Date_value 2>), the unitcan be YEAR, MONTH, DAY, HOUR, etc...6. Find the last name of all employees that were not hired on Tuesday *hint: (UseDATE_FORMAT() function amd the format you need is %W, also use UPPER()7. Find the number of employees in each department who have a manager.8. Find the number of employees for each manager whose employees' minimum salary is greaterthan 5000.9. Find the number of…
arrow_forward
SQL:
Start with the Employee table used in Lab 4.
CREATE TABLE Employee
(
EMPLOYEE_ID INT NOT NULL,
FIRST_NAME CHAR(20),
LAST_NAME CHAR(20),
JOB_LEVEL INT,
SALARY BIGINT,
COMMISSION_PCT INT,
CONSTRAINT PKEmployeeID PRIMARY KEY (EMPLOYEE_ID)
);
INSERT INTO Employee
VALUES
(100,'Steven','King',1,50000,10),
(101,'Neena','Kochhar',1,50000,10),
(102,'Lex','De Haan',2,60000 ,15),
(103,'Alexander','Hunold',2,60000,15),
(104,'Bruce','Ernst',3,70000,25),
(105,'Johann','Ernst',4,75000,30);
Create another table.
CREATE TABLE NumEmployeesByLastName
(
LastName CHAR(20),
NumEmployees INT
);
a. Write a query to initialize the NumEmployeesByLastName table by inserting one row for each last name already in the Employee table, and having the accurate count of the number of employees having that last name. Assume that there are no null values in the Employee table.
After your query, if you execute the following query, you would…
arrow_forward
Assume that the Authors table is already built in the database with the following specifications:
Authors:
Column Name
Data Type
constrains
Authors ID
Author Name
Varchar2(10)
|Varchar2(30)
Primary key
Unique
You Need to Create the Books table with the following specifications
Column Name
Data Type
Constrains
ISBN
Book Title
Book Price
Author id
Number (10)
Varchar2(40)
Number (4,2)
Varchar2(10)
Primary key
Not Null
referencing the Author_ID in
the Author Table
Complete the create statement by drag and drop the correct word:
Create Table lblank (ISBN Number (10) plank,
Book Title Varchar2blank ) Not Null,
Book Price Number(4, 2),
Auther IR blank (10) references Jolank (blank );
Author ID Books Number||Authors Not Nul Varchar2| Primary Key 40
h (United States)
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781285196145
Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:Cengage Learning
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr
Related Questions
- DROP TABLE IF EXISTS Worker; CREATE TABLE Worker ( ); 0 INSERT ); WORKER_ID INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, FIRST NAME TEXT, LAST NAME TEXT, SALARY INTEGER (15), JOINING DATE DATETIME, DEPARTMENT CHAR (25) INTO Worker (WORKER_ID, FIRST_NAME, LAST_NAME, SALARY, JOINING_DATE, DEPARTMENT) VALUES 'Arora', 100000, '14-02-20 09.00.00', 'HR'), (001, 'Monika', (002, 'Niharika', 'Verma' 80000, '14-06-11 09.00.00', 'Admin'), 'HR'), 'Admin'), Admin'), 'Account'), 'Kumar', 75000, '14-01-20 09.00.00', 'Account') DROP TABLE IF EXISTS Bonus; CREATE TABLE Bonus ( ); (003, 'Vishal' 'Singhal', 300000, '14-02-20 09.00.00', (004, 'Amitabh 'Singh', 500000, '14-02-20 09.00.00', (005, 'Vivek' 'Bhati', 500000, '14-06-11 09.00.00'. (006, 'Vipul', 'Diwan' 200000, '14-06-11 09.00.00', (007, 'Satish' (008, 'Geetika', 'Chauhan', 90000, '14-04-11 09.00.00', 'Admin'); WORKER_REF_ID INTEGER, BONUS AMOUNT INTEGER(10), BONUS_DATE DATETIME, FOREIGN KEY (WORKER_REF_ID) REFERENCES Worker (WORKER_ID) ON DELETE…arrow_forwardCREATE TABLE DONORS (donor_id INT NOT NULL,donor_name varchar(255) NOT NULL,donor_age int,PRIMARY KEY (donor_id ));CREATE TABLE DONATIONS(pledge_id INT NOT NULL,pledge_date varchar(255) NOT NULL,amount_pledged int,Is_paid int,donor_id int,PRIMARY KEY (pledge_id ),FOREIGN KEY (donor_id) REFERENCES DONORS(donor_id)); 1. Populate every relation with three rows.arrow_forwardThe Car Maintenance team also wants to store the actual maintenance operations in the database. The team wants to start with a table to store CAR_ID (CHAR(5)), MAINTENANCE_TYPE_ID (CHAR(5)) and MAINTENANCE_DUE (DATE) date for the operation. Create a new table named MAINTENANCES. The PRIMARY_KEY should be the combination of the three fields. The CAR_ID and MAINTENACNE_TYPE_ID should be foreign keys to their original tables. Cascade update and cascade delete the foreign keys.arrow_forward
- drop table Parents_Children;drop table Persons; create table Persons (name varchar(64) primary key,gender char(1) not null); create table Parents_Children (parent varchar(64),child varchar(64),primary key (parent, child),foreign key (parent) references Persons(name),foreign key (child) references Persons(name)); insert into Persons (name, gender) values ('Ann', 'F');insert into Persons (name, gender) values ('Bob', 'M');insert into Persons (name, gender) values ('Cory', 'M');insert into Persons (name, gender) values ('Dave', 'M');insert into Persons (name, gender) values ('Emma', 'F');insert into Persons (name, gender) values ('Fred', 'M');insert into Persons (name, gender) values ('Gab', 'Q');insert into Persons (name, gender) values ('Hil', 'F');insert into Persons (name, gender) values ('Ian', 'M'); insert into Parents_Children (parent, child) values ('Ann', 'Bob');insert into Parents_Children (parent, child) values ('Ann', 'Cory');insert into Parents_Children (parent, child) values…arrow_forwardUsing the Winners table from Figure 12-2, write a parameter query that selects theActor and Actress fields for the year provided by the user.arrow_forwardConsidering Vaccination Database, write queries to: Display the Subject CNIC, Name, Contact, Dose1 Center, and Dose2 Center as shown below: CNIC Name Contact Dose1 Center Dose2 Center 22401-6645321-1 Nasir 3409991112 Lachi Kohat 2 14301-6045321-5 Shahab 3409991112 kohat 3 Dara The subjects who have been vaccinated different types in Dose1 and Dose2. For instance, subjects who were vaccinated ‘Sinovac’ in the first dose, while Pfizer in the second dose.How many Viles of each type have been consumed so far. How many subjects are vaccinated from expired viles. Suggest the name of Incharge for the best performance award based on the highest number of subjects vaccinated on a single dayarrow_forward
- CREATE 3 tables as listed below in your own database. */ CREATE TABLE Customer (CustomerID VARCHAR(20) PRIMARY KEY, CustomerLName VARCHAR(30), CustomerFName VARCHAR(30), CustomerStatus VARCHAR(10)); CREATE TABLE SaleOrder (OrderID INT IDENTITY PRIMARY KEY, CustomerID VARCHAR(20) REFERENCES Customer(CustomerID), OrderDate DATE, OrderAmountBeforeTax INT); CREATE TABLE SaleOrderDetail (OrderID INT REFERENCES SaleOrder(OrderID), ProductID INT, Quantity INT, UnitPrice INT, PRIMARY KEY (OrderID, ProductID)); /* Write a trigger to put the total sale order amount before tax (unit price * quantity for all items included in an order) in the OrderAmountBeforeTax column of SaleOrder. */arrow_forwardTask 2: The Car Maintenance team also wants to store the actual maintenance operations in the database. The team wants to start with a table to store CAR_ID (CHAR(5)), MAINTENANCE_TYPE_ID (CHAR(5)) and MAINTENANCE_DUE (DATE) date for the operation. Create a new table named MAINTENANCES. The PRIMARY_KEY should be the combination of the three fields. The CAR_ID and MAINTENANCE_TYPE_ID should be foreign keys to their original tables. Cascade update and cascade delete the foreign keys. Create a new table to store maintenance operations Test Query DESCRIBE MAINTENANCES Expected Results Field Type Null Key Default Extra CAR_ID char(5) NO PRI NULL MAINTENANCE_TYPE_ID char(5) NO PRI NULL MAINTENANCE_DUE date NO PRI NULLarrow_forwardTask 2: The Car Maintenance team also wants to store the actual maintenance operations in the database. The team wants to start with a table to store CAR_ID (CHAR(5)), MAINTENANCE_TYPE_ID (CHAR(5)) and MAINTENANCE_DUE (DATE) date for the operation. Create a new table named MAINTENANCES. The PRIMARY_KEY should be the combination of the three fields. The CAR_ID and MAINTENACNE_TYPE_ID should be foreign keys to their original tables. Cascade update and cascade delete the foreign keys. Answer in MYSQL pleasearrow_forward
- CREATE TABLE Users( C_Id varchar(8) NOT NULL, LastName Varchar(255) NOT NULL, FirstName varchar(255) NOT NULL, ema il varchar(255), Phone int, PRIMARY KÉY (C_Id) CREATE TABLE Restaurants( R_Id varchar(255) NOT NULL, Rname varchar(255) NOT NULL, Type varchar(255), Raddress varchar(255), Rphone int, Remail varchar(255), PRIMARY KEY(R_Id) ); CREATE TABLE RDate( T_num int NOT NULL, Bdate DATE, Rdate DATE, T_start varchar(255), E_start varchar(255), PRIMARY KEY(T_num) ); CREATE TABLE Book ingInfo( C_Id varchar(8) NOT NULL, R_Id int NOT NÚLL, PRIMARY KEY(C_Id, R_Id), FOREIGN KEY (C_Ià) REFERENCES Users(C Id), FOREIGN KEY (R_Id) REFERENCES Restaurant(R_Id) ); CREATE TABLE Rating( R_Id varchar(255) NÓT NULL, Rating Id varchar(255) NOT NULL, Rate varchar(255) CHECK (Rate>11), Comment LONG, PRIMARY KEY(Rating Id), FOREIGN KEY (R_Id) REFERENCES Restaurants(R_Id) ); Create 1 procedure Create 1 function Create 1 database trigger |arrow_forwardCreate an ADD TRIGGER. Explain what the trigger does. Test and show the related results of this trigger. Table 1: CREATE TABLE BSR_PASSENGER (PASSENGER_ID INT NOT NULL UNIQUE, FULL_NAME VARCHAR(30), COUNTRY VARCHAR(40), CITY VARCHAR (40), PRIMARY KEY (PASSENGER_ID)); Table 2: CREATE TABLE BSR_FLIGHT (FLIGHT_ID INT NOT NULL UNIQUE, AIRLINE_NAME VARCHAR(50), CREW_MEMBERS INT, PRIMARY KEY (FLIGHT_ID)); Table 3: CREATE TABLE BSR_BOOKING (BOOKING_ID INT NOT NULL UNIQUE AUTO_INCREMENT, PASSENGER_ID INT NOT NULL, FLIGHT_ID INT NOT NULL, COST DEC(6,3), PRIMARY KEY (BOOKING_ID), FOREIGN KEY (PASSENGER_ID) REFERENCES BSR_PASSENGER(PASSENGER_ID), FOREIGN KEY (FLIGHT_ID) REFERENCES BSR_FLIGHT(FLIGHT_ID));arrow_forwardAssistance with SQL statements Previous code; CREATE TABLE Lab4program_piershed ( code VARCHAR(5) PRIMARY KEY, name VARCHAR(20), tel VARCHAR(20));CREATE TABLE Lab4course_xxxx ( cid INT PRIMARY KEY, name VARCHAR(20), credits INT, mycode VARCHAR(5), FOREIGN KEY (mycode) REFERENCES Lab4program_xxxx(code)); 1. Insert 3 records into your Lab4program_xxxx table. The code should be "CPS", "TECH", "MATH", or "BIO". Please copy/paste your SQL statements with the output message in the text that shows you successfully insert 3 records to your table. 2. Insert 4 records into your Lab4course_xxxx table with at least 2 different mycode. Please copy/paste your SQL statements with the output message in the text that shows you successfully insert 4 records to your table.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781305627482Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781285196145Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos CoronelPublisher:Cengage LearningA Guide to SQLComputer ScienceISBN:9781111527273Author:Philip J. PrattPublisher:Course Technology Ptr
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781305627482
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781285196145
Author:Steven, Steven Morris, Carlos Coronel, Carlos, Coronel, Carlos; Morris, Carlos Coronel and Steven Morris, Carlos Coronel; Steven Morris, Steven Morris; Carlos Coronel
Publisher:Cengage Learning
A Guide to SQL
Computer Science
ISBN:9781111527273
Author:Philip J. Pratt
Publisher:Course Technology Ptr