(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
- Write SQL code for the following design schema of three tables. The tables should have the following properties: sales table has a primary key on SalesNumber and it is set to AUTO-INCREMENT.products table has a primary key on number and it is set to AUTO-INCREMENT, they is an unique index on prodidsalesdetails table has a primary key on number and it is set to AUTO-INCREMENT, they is an index on prodid. They is a one-to-many relationship between the salesdetails.SalesNumber andsales.SalesNumber fields. There is a one-to-many relationship between the products.prodid and salesdetails.prodid fields. There is to be a delete constraint on the product.prodid field a record in the product table should not be allowed to be deleted if they exist a matching prodid in the salesdetails table. Primary and foreign keys should be implemented in the appropriate tables. Referential Integrity should be enforce at the database level, where appropriate for example, if a sales record is deleted all…arrow_forwardClosely 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_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
- 4 and 5arrow_forwardThe table STUDENT has the attributes STUDENT_ID, NAME, S_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 where the common attributes are S_ID, and SCHOOL_ID. Which of the following creates a table that shows the STUDENT attributes and the corresponding SCHOOL attributes? a. SELECT * FROM STUDENT JOIN SCHOOL USING(SCHOOL_ID) b. SELECT * FROM STUDENT JOIN SCHOOL USING(S_ID) c. SELECT * FROM STUDENT NATURAL JOIN SCHOOL ON S_ID AND SCHOOL.SCHOOL_ID d. SELECT * FROM STUDENT JOIN SCHOOL ON STUDENT.S_ID = SCHOOL.SCHOOL_IDarrow_forwardThe relational database below contains two related tables - “Supplier” and “Product”: “Product” table: Primary key = Prod-code, Foreign key = Supp-code Prod-code Prod -name Prod -desript Prod -stocktype Prod -stocklevel Prod -expireDate Supp-code 10010 aaa qwert 615 123445677 2017-11-14 501 10011 bbb asdfgg 615 234567899 2017-11-16 501 10012 ccc zxxcvv 234 345678900 2017-11-13 502 10013 eee ytuytu 234 454577777 2017-10-13 503 10014 jjj werewr 231 436436885 2017-10-23 503 10015 sdg rtyrtyry 275 676446322 2017-10-30 504 10016 ewt erterter 789 232317879 2017-12-30 501 “Supplier” table: Primary key = Supp -code, No Foreign key Supp -code Supp -lname Supp -fname Supp -Initial Supp -areacode Supp -phone 501 xxx qwert F 615 123445678 502 yyy asdfgg B 615 234567890 503 zzz zxxcvv X 234 345678901…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