(a)
UNION set operator:
The UNION set operator is used to combine the output of two or more than two queries and produce a result. The produced result contains unique values.
Syntax:
QUERY UNION QUERY;
Consider two tables:
Table creation:
CREATE TABLE VENDOR(VEND_CODE INT PRIMARY KEY);
CREATE TABLE PRODUCT(PROD_CODE VARCHAR(5), VEND_CODE INT,FOREIGN KEY (VEND_CODE) REFERENCES VENDOR (VEND_CODE));
Inserting values:
INSERT INTO VENDOR VALUES(123);
INSERT INTO VENDOR VALUES(124);
INSERT INTO VENDOR VALUES(125);
INSERT INTO VENDOR VALUES(126);
INSERT INTO PRODUCT VALUES('ABC', 125);
INSERT INTO PRODUCT VALUES('DEF', 124);
INSERT INTO PRODUCT VALUES('GHI', 124);
INSERT INTO PRODUCT VALUES('JKL', 123);
(b)
UNION ALL set operator:
The UNION ALL set operator is used to combine the output of two or more than two queries and produce a result. The produced result contains duplicate values.
Syntax:
QUERY UNION ALL QUERY;
Consider two tables:
Table creation:
CREATE TABLE VENDOR(VEND_CODE INT PRIMARY KEY);
CREATE TABLE PRODUCT(PROD_CODE VARCHAR(5), VEND_CODE INT,FOREIGN KEY (VEND_CODE) REFERENCES VENDOR (VEND_CODE));
Inserting values:
INSERT INTO VENDOR VALUES(123);
INSERT INTO VENDOR VALUES(124);
INSERT INTO VENDOR VALUES(125);
INSERT INTO VENDOR VALUES(126);
INSERT INTO PRODUCT VALUES('ABC', 125);
INSERT INTO PRODUCT VALUES('DEF', 124);
INSERT INTO PRODUCT VALUES('GHI', 124);
INSERT INTO PRODUCT VALUES('JKL', 123);
(c)
INTERSECT set operator:
The INTERSECT set operator is used to combine the output of two or more than two queries and produce a result. The produced result contains the values (rows) that are common in both the tables.
Syntax:
QUERY INTERSECT QUERY;
Consider two tables:
Table creation:
CREATE TABLE VENDOR(VEND_CODE INT PRIMARY KEY);
CREATE TABLE PRODUCT(PROD_CODE VARCHAR(5), VEND_CODE INT,FOREIGN KEY (VEND_CODE) REFERENCES VENDOR (VEND_CODE));
Inserting values:
INSERT INTO VENDOR VALUES(123);
INSERT INTO VENDOR VALUES(124);
INSERT INTO VENDOR VALUES(125);
INSERT INTO VENDOR VALUES(126);
INSERT INTO PRODUCT VALUES('ABC', 125);
INSERT INTO PRODUCT VALUES('DEF', 124);
INSERT INTO PRODUCT VALUES('GHI', 124);
INSERT INTO PRODUCT VALUES('JKL', 123);
(d)
EXCEPT/ MINUS set operator:
The MINUS set operator is used to combine the output of two or more than two queries and produce a result. The produced result contains the values (rows) that appear in the first table but not in the second table. The word “EXCEPT” can also be used in the place of “MINUS”.
Syntax:
QUERY EXCEPT QUERY;
Consider two tables:
Table creation:
CREATE TABLE VENDOR(VEND_CODE INT PRIMARY KEY);
CREATE TABLE PRODUCT(PROD_CODE VARCHAR(5), VEND_CODE INT,FOREIGN KEY (VEND_CODE) REFERENCES VENDOR (VEND_CODE));
Inserting values:
INSERT INTO VENDOR VALUES(123);
INSERT INTO VENDOR VALUES(124);
INSERT INTO VENDOR VALUES(125);
INSERT INTO VENDOR VALUES(126);
INSERT INTO PRODUCT VALUES('ABC', 125);
INSERT INTO PRODUCT VALUES('DEF', 124);
INSERT INTO PRODUCT VALUES('GHI', 124);
INSERT INTO PRODUCT VALUES('JKL', 123);
Trending nowThis is a popular solution!
Chapter 8 Solutions
Database Systems: Design, Implementation, & Management
- Consider the following schema and write the following queries in relational algebra. Product(pid, pname, pcolour, price, supplier, year_manufacture) Select the records where product is 'shoes'. Select the records where product colour is 'red' and 'price' is 450. 3. Select records from Product table where supplier is 'Davidson' and price is 500 or those products manufactured after 2018 . 4.Project the columns named as pid and supplier from the Product table.arrow_forwardAssume you have a vehicle table with a surrogate key vehicle_id column and VIN (Vehicle Identification Number) column and some other columns. You want to designate a unique index on the vehicle_id and VIN columns because together they filter on the joining column with the highest cardinality (or degree of uniqueness). Write the syntax to add a unique index on the vehicle_id and VIN columns triggered by joins on the surrogate key column?arrow_forwardSTUDENT Student# Std-Name Address 1 Smith Jeddah 2 Bob Buraidah 3 Alice Dammam COURSE Student# Course Code Course-Name 1 IT241 Operating System 2 IT210 Computer Network 2 IT445 Decision Support System Write a query using the Right Outer Join to retrieve the record from the two relations. Also, construct the table displaying the output of your query. Consider the following enterprise scenario and answer the following questions. ABC is a wholesale company that sells electrical equipment and provides a website from which customers can inquiry about products and identify what they want to buy. When costumers order electrical equipment, they place their order on the ABC website. ABC does not own or hold any equipment as inventory. Rather, the ABC orders the equipment from the appropriate supplier and ranges for the equipment to be shipped directly from the supplier to the customers. The…arrow_forward
- Answer questions 2.1 to 2.4 based on the following schema. Note that primary keys are in BOLD. Note also that attributes with the same name in different tables are foreign keys. For example, doctorID in the Treatment table is a foreign key that refers to the Doctor table. Doctor(doctorId:integer, specialtyID:integer, firstName:varchar(20), lastName:varchar(20), salary:numeric(11,2)) Specialty(specialtyID:integer, specialtyName:varchar(20), specialtyCost:numeric(11,2)) Treatment(doctorId:integer, patientSSN:integer, dateTreated:date, costOfTreatment:numeric(11,2)) Patient(patientSSN:integer, firstName:varchar(20), lastName:varchar(20), street:varchar(30), city:varchar(15), state:char(2),zipCode:integer(5)) 1. Write an SQL statement to increase the cost of all Specialty treatment by 2.5% 2. Write a SQL statement to delete all treatment rows that were done before 2015 and cost less than $500.arrow_forwardAnswer questions 2.1 to 2.4 based on the following schema. Note that primary keys are in BOLD. Note also that attributes with the same name in different tables are foreign keys. For example, doctorID in the Treatment table is a foreign key that refers to the Doctor table. Doctor(doctorId:integer, specialtyID:integer, firstName:varchar(20), lastName:varchar(20), salary:numeric(11,2)) Specialty(specialtyID:integer, specialtyName:varchar(20), specialtyCost:numeric(11,2)) Treatment(doctorId:integer, patientSSN:integer, dateTreated:date, costOfTreatment:numeric(11,2)) Patient(patientSSN:integer, firstName:varchar(20), lastName:varchar(20), street:varchar(30), city:varchar(15), state:char(2),zipCode:integer(5)) 2.3) Write an SQL statement to increase the cost of all Specialty treatment by 2.5% 2.4) Write a SQL statement to delete all treatment rows that were done before 2015 and cost less than $500. 2.5) Write an SQL statement to select all Specialties where the specialtytName has a null…arrow_forwardTranscribed Image Text Based on the following table, write the relational schema that meets 1NF, 2NF and 3NF requirements. You are required to draw the dependency diagram for 2NF. TABLE 6: CUSTOMER-SHARE RECORDS SAMPLE | CompanyNo | CustiD CustName Brokerl 122 Ali CompanyType DateBought Share BoughtPrice |Dividend |Consumer Products 23/7/2009 450 BrokerName CompanyName Nestle (M) Sơn. Bhd. |Cheetah Holdings Sdn. Bhd. Properties Victory Manufacturing Sdn. Bhd |Manufacturing Berjaya Hotel Sdn. Bhd. Cheetah Holdings Sdn. Bhd. Properties |Berjaya Hotel Sdn. Bhd. Nestle (M) Sơn. Bhd. B22 Melaka Securities 23 0.80 1.10% 1/9/2009 100 15/10/2010 20/1/2011 30/5/2009 19/4/2010 45 2.00 2.00% 301 Mary B12 Kuala Lumpur City Securities 50 0.50 0.50% 11 21 Hotel 220 0.50 1.00% 45 50 3.10 2.00% 1001 Jeffry Hotel |Consumer Products 10/8/2011 | 1000 822 Melaka Securities 21 50 1.80 1.00% 23 1.20 1.10%arrow_forward
- 1NF to 4NF Data Normalization is needed. Each relation (table) represents a single subject. For example, a COURSE table will contain only data that directly pertain to courses. Each row/column intersection contains only one value and not a group of values. No data item will be unnecessarily stored in more than one table (tables have minimum controlled redundancy). All nonprime attributes in a relation (table) are dependent on the primary key - the entire primary key and nothing but the primary key. Each relation (table) has no insertion, update, or deletion anomalies, which ensures the integrity and consistency of the data.arrow_forwardFind one type-2 functional dependency in the grade table Table GRADE Student ID Student Name Student Address Course ID Course Name Term Grade 700323570 Alice Roslyn, NY IT001 Information Systems 2015 Fall 3.5 700323570 Alice Roslyn, NY IT002 Python Programming 2015 Fall 4.0 700323580 Bob Mineola, NY IT002 Python Programming 2014 Spring 2.5 700323578 Cindy Jericho, NY IT110 Database 2015 Spring 3.7 700323578 Cindy Jericho, NY IT001 Information Systems 2015 Fall 4.0 700323582 Zachary Kearny, NJ IT001 Information Systems 2015 Fall 3.6 700323582 Zachary Kearny, NJ IT120 Network 2016 Spring 3.8arrow_forwardQuestion 3: Create the DDL statements to create the tables described in your modified ER diagram in question 2: DDL Statement: CREATE TABLE School ( school_code integer Primary Key(10), location varchar(25), name varchar(10) ); CREATE TABLE Professors ( staff_id integer(10), name varchar(20), school varchar(30) ); CREATE TABLE Course ( subject_code varchar(10), school varchar(30), name varchar(10) ); CREATE TABLE Subject ( subject_code(10), school varchar(30), name varchar(10) ); CREATE TABLE Student ( student_id number(10), name varchar(10), address varchar(30), phone number(10) ); Table Description desc table School; Select * from School; Name Null Type school_code Not null integer location Not null varchar(25) name Not null varchar(10) desc table Professor; Select * from Professor; Name Null Type staff_id Not null number(10) name varchar(20) school varchar(30) desc table Course; Select * from…arrow_forward
- Consider the E-R diagram in Figure 8.7 showing entity set instructor. Give an SQL schema definition corresponding to the E-R diagram, treating phone number as an array of 10 elements, using Oracle or PostgreSQL syntax.arrow_forwardwhich rules apply to desigining table with less redundancy? a) Binary Relationship b) Reflective Relationship c) Weak entity d) Normal formarrow_forwardCreate a view of the Join of Deposit and Withdraw transactions to Bank Branch UNION with the join of Bill Payment and Debit Purchase, or Return transactions to Merchant (i.e., all transactions with appropriate reference name.). BranchNbr stores RefNbr of either 'D', OR 'W' transactions, and MerchantNbr stores RefNbr of either 'B', 'P', or 'R' transactions. GIVEN THE BELOW: --THIS CREATES THE TRANSACTION TABLE: CREATE TABLE Transaction ( TxNbr INT PRIMARY KEY, AccountNbr INT, TxTypeCode VARCHAR(250), TxDate DATE, TxTime TIMESTAMP, TxAmount FLOAT, RefNbr INT, FOREIGN KEY (AccountNbr)REFERENCES Account(AccountNbr), FOREIGN KEY (TxTypeCode) REFERENCES TxType(TxTypeCode)); --THIS CREATES THE BANK BRANCH TABLE:CREATE TABLE BankBranch ( BranchNbr INT PRIMARY KEY, BranchName VARCHAR(250)); --THIS CREATES THE MERCHANT TABLE:CREATE TABLE Merchant ( MerchantNbr INT PRIMARY KEY, MerchantName VARCHAR(250)); -- Insert test data…arrow_forward
- 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 Learning