(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
- Table 1 is the Sales table, which is an unnormalized table. The description of the Sales table are SNUM = salesman number, CNUM = customer number, WNUM = warehouse number, SAMOUNT = sale amount, etc. a.)Write down four functional dependencies (FDs) that are valid in the Sales table b.)Write down the Sales table's normalization result that is in the 2NF, but not in the 3NF.Explain why the table is not in the 3NF.arrow_forwardAssume the EMPLOYEE table contains four attributes, ID, DEPT, SALARY and NAME, and has the following rows ID DEPT SALARY NAME 100 SALES 40000 Smith 101 RD 38000 Terry 102 HR 60000 David 103 SALES 58000 Ellie 104 RD 70000 Judy The DEPARTMENT table contains two attributes, DEPTNAME and PHONE, and has the following rows: DEPTNAME PHONE RD 8596001234 SALES 8596005555 HR 8596009876 A.) The EMPLOYEE table needs to enforce the following integrity constraints: • The ID is the primary key. • The DEPT column is a foreign key that references the DEPTNAME in the DEPARTMENT table, so that any value that appears in the DEPT column should also exist in the DEPARTMENT table. • The value for the NAME column can never be null. What should be the statement used to create the EMPLOYEE table, if 1) the table was created as a partitioned table such…arrow_forwardThe table STUDENT has the attributes STUDENT_ID, NAME, SCHOOL_ID, and ADDR. The table SCHOOL has the attributes SCHOOL_ID, NAME, and STATE_CODE. Assume that there is a 1:N relation between SCHOOL and STUDENT. Which of the following creates a table that shows the STUDENT attributes and the corresponding SCHOOL attributes? a. SELECT * SCHOOL_ID FROM STUDENT JOIN SCHOOL b. SELECT * SCHOOL_ID FROM STUDENT JOIN SCHOOL USING(SCHOOL_ID) c. SELECT * SCHOOL_ID FROM STUDENT NATURAL JOIN SCHOOL d. SELECT * SCHOOL_ID FROM STUDENT, SCHOOL WHERE SCHOOL_ID = SCHOOL_IDarrow_forward
- Closely examine the following tables and use it to answer the questions that follow: department course student_type student_category Student registration registration_type Suppose that the following are true: - all id column are primary keys in whichever table they are - the dept_id in course table is foreign key that is referencing the id column in the department table - the foreign keys stud_type_id, stud_cat_id in the student table are referencing the id columns in the student_type and student_category tables respectively. - the coursecode and stud_id columns in the registration table are foreign keys in the course and student tables respectively. 1. Design an Entity Relationship Diagram for the system above. 2. Write query that would return the names and contacts of all Local students. 3. Write a query that would return names, contact and locations of all departments that has a location text with Ave 3 as part of it. [hint: use the LIKE clause with “_” or “%”] 4. What would…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_forward1. The data type for Borrower_name in Borrowers Table is: A. Short text C. Currency B. Long text D. Yes/No Borrowers Field Name Borrower ID Borrower Name Phone num Membership_activation Data Type AutoNumber Short Text Short Text Yes/Noarrow_forward
- Implement a new independent entity phone in the Sakila database. Attributes and relationships are shown in the diagram below The diagram uses Sakila naming conventions. Follow the Sakila conventions for your table and column names: All lower case Underscore separator between root and suffix Foreign keys have the same name as referenced primary key Write CREATE TABLE and ALTER TABLE statements that: Implement the entity as a new phone table. Implement the has relationships as foreign keys in the Sakila customer, staff, and store tables. Remove the existing phone column from the Sakila address table. Step 2 requires adding a foreign key constraint to an existing table. Ex: ALTER TABLE customer ADD FOREIGN KEY (phone_id) REFERENCES phone(phone_id) ON DELETE SET NULL ON UPDATE CASCADE; Specify data types as follows: phone_id, phone_number, and country_code have data type INT. phone_type has date type VARCHAR(12) and contains strings like 'Home', 'Mobile', and 'Other'. Apply these…arrow_forwardWrite the SQL statements to create all of the necessary tables to represent the above diagram, representing as many constraints as possible. Note: you do not need to worry about specifying types for the fields, but you do need to provide suitable foreign key option(s). When playing a game, the home team name should be stored in attribute htname and the away team name should be stored in atname.arrow_forwardImplement a new independent entity phone in the Sakila database. Attributes and relationships are shown in the following diagram: The diagram uses Sakila naming conventions. Follow the Sakila conventions for your table and column names: All lower case Underscore separator between root and suffix Foreign keys have the same name as referenced primary key Write CREATE TABLE and ALTER TABLE statements that: Implement the entity as a new phone table. Implement the has relationships as foreign keys in the Sakila customer, staff, and store tables. Remove the existing phone column from the Sakila address table. Step 2 requires adding a foreign key constraint to an existing table. Ex: ALTER TABLE customer ADD FOREIGN KEY (phone_id) REFERENCES phone(phone_id) ON DELETE SET NULL ON UPDATE CASCADE; Specify data types as follows: phone_id, phone_number, and country_code have data type INT. phone_type has date type VARCHAR(12) and contains strings like 'Home', 'Mobile', and 'Other'. Apply…arrow_forward
- Implement a new independent entity phone in the Sakila database. Attributes and relationships are shown in the following diagram: The diagram uses Sakila naming conventions. Follow the Sakila conventions for your table and column names: All lower case Underscore separator between root and suffix Foreign keys have the same name as referenced primary key Write CREATE TABLE and ALTER TABLE statements that: Implement the entity as a new phone table. Implement the has relationships as foreign keys in the Sakila customer, staff, and store tables. Remove the existing phone column from the Sakila address table. Step 2 requires adding a foreign key constraint to an existing table. Ex: ALTER TABLE customer ADD FOREIGN KEY (phone_id) REFERENCES phone(phone_id) ON DELETE SET NULL ON UPDATE CASCADE; Specify data types as follows: phone_id, phone_number, and country_code have data type INT. phone_type has date type VARCHAR(12) and contains strings like 'Home', 'Mobile', and 'Other'. Apply…arrow_forwardImplement a new independent entity phone in the Sakila database. Attributes and relationships are shown in the following diagram: The diagram uses Sakila naming conventions. Follow the Sakila conventions for your table and column names: All lower case Underscore separator between root and suffix Foreign keys have the same name as referenced primary key Write CREATE TABLE and ALTER TABLE statements that: Implement the entity as a new phone table. Implement the has relationships as foreign keys in the Sakila customer, staff, and store tables. Remove the existing phone column from the Sakila address table. Step 2 requires adding a foreign key constraint to an existing table. Ex: ALTER TABLE customer ADD FOREIGN KEY (phone_id) REFERENCES phone(phone_id) ON DELETE SET NULL ON UPDATE CASCADE; Specify data types as follows: phone_id, phone_number, and country_code have data type INT. phone_type has date type VARCHAR(12) and contains strings like 'Home', 'Mobile', and 'Other'. Apply…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
- 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