Deck 4: SQL: Data Definition, Constraints, and Basic Queries and Updates

ملء الشاشة (f)
exit full mode
سؤال
    Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. What are the referential integrity constraints that should hold on the schema? Write appropriate SQL DDL statements to define the database.<div style=padding-top: 35px>     Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. What are the referential integrity constraints that should hold on the schema? Write appropriate SQL DDL statements to define the database.<div style=padding-top: 35px>
Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. What are the referential integrity constraints that should hold on the schema? Write appropriate SQL DDL statements to define the database.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
      Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.<div style=padding-top: 35px>       Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.<div style=padding-top: 35px>       Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.<div style=padding-top: 35px>
Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.
سؤال
  Consider the LIBRARY relational database schema of Figure 4.6. Choose the appropriate action (reject, cascade, set to null, set to default) for each referential integrity constraint, both for the deletion of a referenced tuple, and for the update of a primary key attribute value in a referenced tuple. Justify your choices.<div style=padding-top: 35px>
Consider the LIBRARY relational database schema of Figure 4.6. Choose the appropriate action (reject, cascade, set to null, set to default) for each referential integrity constraint, both for the deletion of a referenced tuple, and for the update of a primary key attribute value in a referenced tuple. Justify your choices.
سؤال
  Write appropriate SQL DDL statements for declaring the LIBRARY relational database schema of Figure 4.6. Specify the keys and referential triggered actions.<div style=padding-top: 35px>
Write appropriate SQL DDL statements for declaring the LIBRARY relational database schema of Figure 4.6. Specify the keys and referential triggered actions.
سؤال
How can the key and foreign key constraints be enforced by the DBMS? Is the enforcement technique you suggest difficult to implement? Can the constraint checks be executed in an efficient manner when updates are applied to the database?
سؤال
Exercise 3.11
Suppose that each of the following Update operations is applied directly to
the database state shown in Figure 3.6.
Exercise 3.11 Suppose that each of the following Update operations is applied directly to the database state shown in Figure 3.6.   Discuss all integrity constraints violated by each operation, if any, and the different ways of enforcing these constraints. a. Insert <'Robert', 'F', 'Scott', '943775543', '1972-06-21', '2365 Newcastle Rd, Bellaire, TX', M, 58000, '888665555', 1> into EMPLOYEE. b. Insert <'ProductA', 4, 'Bellaire', 2> into PROJECT. c. Insert <'Production', 4, '943775543', '2007-10-01'> into DEPARTMENT. d. Insert <'677678989', NULL, '40.0'> into WORKS_ON. e. Insert <'453453453', 'John', 'M', '1990-12-12', 'spouse'> into DEPENDENT. f. Delete the WORKS_ON tuples with Essn = '333445555'. g. Delete the EMPLOYEE tuple with Ssn = '987654321'. h. Delete the PROJECT tuple with Pname = 'ProductX'. i. Modify the Mgr_ssn and Mgr_start_date of the DEPARTMENT tuple with Dnumber = 5 to '123456789' and '2007-10-01', respectively. j. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn = '999887777' to '943775543'. k. Modify the Hours attribute of the WORKS_ON tuple with Essn = '999887777' and Pno = 10 to '5.0'. Specify the updates of Exercise 3.11 using the SQL update commands.<div style=padding-top: 35px> Discuss all integrity constraints violated by each operation, if any, and the different ways of enforcing these constraints.
a. Insert <'Robert', 'F', 'Scott', '943775543', '1972-06-21', '2365 Newcastle Rd,
Bellaire, TX', M, 58000, '888665555', 1> into EMPLOYEE.
b. Insert <'ProductA', 4, 'Bellaire', 2> into PROJECT.
c. Insert <'Production', 4, '943775543', '2007-10-01'> into DEPARTMENT.
d. Insert <'677678989', NULL, '40.0'> into WORKS_ON.
e. Insert <'453453453', 'John', 'M', '1990-12-12', 'spouse'> into DEPENDENT.
f. Delete the WORKS_ON tuples with Essn = '333445555'.
g. Delete the EMPLOYEE tuple with Ssn = '987654321'.
h. Delete the PROJECT tuple with Pname = 'ProductX'.
i. Modify the Mgr_ssn and Mgr_start_date of the DEPARTMENT tuple with
Dnumber = 5 to '123456789' and '2007-10-01', respectively.
j. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn =
'999887777' to '943775543'.
k. Modify the Hours attribute of the WORKS_ON tuple with Essn =
'999887777' and Pno = 10 to '5.0'.
Specify the updates of Exercise 3.11 using the SQL update commands.
سؤال
  Specify the following queries in SQL on the database schema of Figure 1.2. (a) Retrieve the names of all senior students majoring in 'COSC' (computer science). (b) Retrieve the names of all courses taught by professor King in 85 and 86. (c) For each section taught by professor King, retrieve the course number, semester, year, and number of students who took the section. (d) Retrieve the name and transcript of each senior student (Class=5) majoring in COSC. Transcript includes course name, course number, credit hours, semester, year, and grade for each course completed by the student. (e) Retrieve the names and major departments of all straight A students (students who have a grade of A in all their courses). (f) Retrieve the names and major departments of all students who do not have any grade of A in any of their courses.<div style=padding-top: 35px>
Specify the following queries in SQL on the database schema of Figure 1.2.
(a) Retrieve the names of all senior students majoring in 'COSC' (computer science).
(b) Retrieve the names of all courses taught by professor King in 85 and 86.
(c) For each section taught by professor King, retrieve the course number, semester, year, and number of students who took the section.
(d) Retrieve the name and transcript of each senior student (Class=5) majoring in COSC. Transcript includes course name, course number, credit hours, semester, year, and grade for each course completed by the student.
(e) Retrieve the names and major departments of all straight A students (students who have a grade of A in all their courses).
(f) Retrieve the names and major departments of all students who do not have any grade of A in any of their courses.
سؤال
  Write SQL update statements to do the following on the database schema shown in Figure 1.2. (a) Insert a new student < 'Johnson', 25, 1, 'MATH' > in the database. (b) Change the class of student 'Smith' to 2. (c) Insert a new course < 'Knowledge Engineering','COSC4390', 3,'COSC' > . (d) Delete the record for the student whose name is 'Smith' and student number is 17.<div style=padding-top: 35px>
Write SQL update statements to do the following on the database schema shown in Figure 1.2.
(a) Insert a new student < 'Johnson', 25, 1, 'MATH' > in the database.
(b) Change the class of student 'Smith' to 2.
(c) Insert a new course < 'Knowledge Engineering','COSC4390', 3,'COSC' > .
(d) Delete the record for the student whose name is 'Smith' and student number is 17.
سؤال
     Consider the EMPLOYEE table's constraint EMPSUPERFK as specified in Figure 4.2 is changed to read as follows: CONSTRAINT EMPSUPERFK FOREIGN KEY (SUPERSSN) REFERNCES EMPLOYEE(SSN) ON DELETE CASCADE ON UPDATE CASCADE, Answer the following questions: a. What happens when the following command is run on the database state shown in Figure 3.6? DELETE EMPLOYEE WHERE LNAME = 'Borg' b. Is it better to CASCADE or SET NULL in case of EMPSUPERFK constraint ON DELETE?<div style=padding-top: 35px>

     Consider the EMPLOYEE table's constraint EMPSUPERFK as specified in Figure 4.2 is changed to read as follows: CONSTRAINT EMPSUPERFK FOREIGN KEY (SUPERSSN) REFERNCES EMPLOYEE(SSN) ON DELETE CASCADE ON UPDATE CASCADE, Answer the following questions: a. What happens when the following command is run on the database state shown in Figure 3.6? DELETE EMPLOYEE WHERE LNAME = 'Borg' b. Is it better to CASCADE or SET NULL in case of EMPSUPERFK constraint ON DELETE?<div style=padding-top: 35px>
Consider the EMPLOYEE table's constraint EMPSUPERFK as specified in Figure 4.2 is changed to read as follows: CONSTRAINT EMPSUPERFK FOREIGN KEY (SUPERSSN) REFERNCES EMPLOYEE(SSN) ON DELETE CASCADE ON UPDATE CASCADE, Answer the following questions:
a. What happens when the following command is run on the database state shown in Figure 3.6?
DELETE EMPLOYEE WHERE LNAME = 'Borg'
b. Is it better to CASCADE or SET NULL in case of EMPSUPERFK constraint ON DELETE?
سؤال
  Write SQL statements to create a table EMPLOYEE_BACKUP backup of EMPLOYEE table shown in Figure 3.6.<div style=padding-top: 35px>
Write SQL statements to create a table EMPLOYEE_BACKUP backup of EMPLOYEE table shown in Figure 3.6.
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/10
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 4: SQL: Data Definition, Constraints, and Basic Queries and Updates
1
    Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. What are the referential integrity constraints that should hold on the schema? Write appropriate SQL DDL statements to define the database.     Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. What are the referential integrity constraints that should hold on the schema? Write appropriate SQL DDL statements to define the database.
Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1. What are the referential integrity constraints that should hold on the schema? Write appropriate SQL DDL statements to define the database.
The following referential integrity constraints should hold (we use the notation:
R.(A1, ..., An) -- > S.(B1, ..., Bn)
to represent a foreign key from the attributes A1, ..., An of R (the referencing relation) to S (the referenced relation)):
PREREQUISITE.(CourseNumber) -- > COURSE.(CourseNumber)
PREREQUISITE.(PrerequisiteNumber) -- > COURSE.(CourseNumber)
SECTION.(CourseNumber) -- > COURSE.(CourseNumber)
GRADE_REPORT.(StudentNumber) -- > STUDENT.(StudentNumber)
GRADE_REPORT.(SectionIdentifier) -- > SECTION.(SectionIdentifier)
One possible set of CREATE TABLE statements to define the database is given below.
CREATE TABLE STUDENT ( Name VARCHAR(30) NOT NULL,
StudentNumber INTEGER NOT NULL,
Class CHAR NOT NULL,
Major CHAR(4),
PRIMARY KEY (StudentNumber) );
CREATE TABLE COURSE ( CourseName VARCHAR(30) NOT NULL,
CourseNumber CHAR(8) NOT NULL,
CreditHours INTEGER,
Department CHAR(4),
PRIMARY KEY (CourseNumber),
UNIQUE (CourseName) );
CREATE TABLE PREREQUISITE ( CourseNumber CHAR(8) NOT NULL,
PrerequisiteNumber CHAR(8) NOT NULL,
PRIMARY KEY (CourseNumber, PrerequisiteNumber),
FOREIGN KEY (CourseNumber) REFERENCES
COURSE (CourseNumber),
FOREIGN KEY (PrerequisiteNumber) REFERENCES
COURSE (CourseNumber) );
CREATE TABLE SECTION ( SectionIdentifier INTEGER NOT NULL,
CourseNumber CHAR(8) NOT NULL,
Semester VARCHAR(6) NOT NULL,
Year CHAR(4) NOT NULL,
Instructor VARCHAR(15),
PRIMARY KEY (SectionIdentifier),
FOREIGN KEY (CourseNumber) REFERENCES
COURSE (CourseNumber) );
CREATE TABLE GRADE_REPORT ( StudentNumber INTEGER NOT NULL,
SectionIdentifier INTEGER NOT NULL,
Grade CHAR,
PRIMARY KEY (StudentNumber, SectionIdentifier),
FOREIGN KEY (StudentNumber) REFERENCES
STUDENT (StudentNumber),
FOREIGN KEY (SectionIdentifier) REFERENCES
SECTION (SectionIdentifier) );
2
      Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.       Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.       Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.
Consider the database shown in Figure 1.2, whose schema is shown in Figure 2.1.What are the referential integrity constraints that should hold on the schema? use the AIRLINE schema of Figure 3.8.
The following referential integrity constraints should hold:
FLIGHT_LEG.(FLIGHT_NUMBER) -- > FLIGHT.(NUMBER)
FLIGHT_LEG.(DEPARTURE_AIRPORT_CODE) -- > AIRPORT.(AIRPORT_CODE)
FLIGHT_LEG.(ARRIVAL_AIRPORT_CODE) -- > AIRPORT.(AIRPORT_CODE)
LEG_INSTANCE.(FLIGHT_NUMBER, LEG_NUMBER) -- >
FLIGHT_LEG.(FLIGHT_NUMBER, LEG_NUMBER)
LEG_INSTANCE.(AIRPLANE_ID) -- > AIRPLANE.(AIRPLANE_ID)
LEG_INSTANCE.(DEPARTURE_AIRPORT_CODE) -- > AIRPORT.(AIRPORT_CODE)
LEG_INSTANCE.(ARRIVAL_AIRPORT_CODE) -- > AIRPORT.(AIRPORT_CODE)
FARES.(FLIGHT_NUMBER) -- > FLIGHT.(NUMBER)
CAN_LAND.(AIRPLANE_TYPE_NAME) -- > AIRPLANE_TYPE.(TYPE_NAME)
CAN_LAND.(AIRPORT_CODE) -- > AIRPORT.(AIRPORT_CODE)
AIRPLANE.(AIRPLANE_TYPE) -- > AIRPLANE_TYPE.(TYPE_NAME)
SEAT_RESERVATION.(FLIGHT_NUMBER, LEG_NUMBER, DATE) -- >
LEG_INSTANCE.(FLIGHT_NUMBER, LEG_NUMBER, DATE)
One possible set of CREATE TABLE statements to define the database is given below.
CREATE TABLE AIRPORT ( AIRPORT_CODE CHAR(3) NOT NULL,
NAME VARCHAR(30) NOT NULL,
CITY VARCHAR(30) NOT NULL,
STATE VARCHAR(30),
PRIMARY KEY (AIRPORT_CODE) );
CREATE TABLE FLIGHT ( NUMBER VARCHAR(6) NOT NULL,
AIRLINE VARCHAR(20) NOT NULL,
WEEKDAYS VARCHAR(10) NOT NULL,
PRIMARY KEY (NUMBER) );
CREATE TABLE FLIGHT_LEG ( FLIGHT_NUMBER VARCHAR(6) NOT NULL,
LEG_NUMBER INTEGER NOT NULL,
DEPARTURE_AIRPORT_CODE CHAR(3) NOT NULL,
SCHEDULED_DEPARTURE_TIME TIMESTAMP WITH TIME ZONE,
ARRIVAL_AIRPORT_CODE CHAR(3) NOT NULL,
SCHEDULED_ARRIVAL_TIME TIMESTAMP WITH TIME ZONE,
PRIMARY KEY (FLIGHT_NUMBER, LEG_NUMBER),
FOREIGN KEY (FLIGHT_NUMBER) REFERENCES FLIGHT (NUMBER),
FOREIGN KEY (DEPARTURE_AIRPORT_CODE) REFERENCES
AIRPORT (AIRPORT_CODE),
FOREIGN KEY (ARRIVAL_AIRPORT_CODE) REFERENCES
AIRPORT (AIRPORT_CODE) );
CREATE TABLE LEG_INSTANCE ( FLIGHT_NUMBER VARCHAR(6) NOT NULL,
LEG_NUMBER INTEGER NOT NULL,
LEG_DATE DATE NOT NULL,
NO_OF_AVAILABLE_SEATS INTEGER,
AIRPLANE_ID INTEGER,
DEPARTURE_AIRPORT_CODE CHAR(3),
DEPARTURE_TIME TIMESTAMP WITH TIME ZONE,
ARRIVAL_AIRPORT_CODE CHAR(3),
ARRIVAL_TIME TIMESTAMP WITH TIME ZONE,
PRIMARY KEY (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE),
FOREIGN KEY (FLIGHT_NUMBER, LEG_NUMBER) REFERENCES
FLIGHT_LEG (FLIGHT_NUMBER, LEG_NUMBER),
FOREIGN KEY (AIRPLANE_ID) REFERENCES
AIRPLANE (AIRPLANE_ID),
FOREIGN KEY (DEPARTURE_AIRPORT_CODE) REFERENCES
AIRPORT (AIRPORT_CODE),
FOREIGN KEY (ARRIVAL_AIRPORT_CODE) REFERENCES
AIRPORT (AIRPORT_CODE) );
CREATE TABLE FARES ( FLIGHT_NUMBER VARCHAR(6) NOT NULL,
FARE_CODE VARCHAR(10) NOT NULL,
AMOUNT DECIMAL(8,2) NOT NULL,
RESTRICTIONS VARCHAR(200),
PRIMARY KEY (FLIGHT_NUMBER, FARE_CODE),
FOREIGN KEY (FLIGHT_NUMBER) REFERENCES FLIGHT (NUMBER) );
CREATE TABLE AIRPLANE_TYPE ( TYPE_NAME VARCHAR(20) NOT NULL,
MAX_SEATS INTEGER NOT NULL,
COMPANY VARCHAR(15) NOT NULL,
PRIMARY KEY (TYPE_NAME) );
CREATE TABLE CAN_LAND ( AIRPLANE_TYPE_NAME VARCHAR(20) NOT NULL,
AIRPORT_CODE CHAR(3) NOT NULL,
PRIMARY KEY (AIRPLANE_TYPE_NAME, AIRPORT_CODE),
FOREIGN KEY (AIRPLANE_TYPE_NAME) REFERENCES
AIRPLANE_TYPE (TYPE_NAME),
FOREIGN KEY (AIRPORT_CODE) REFERENCES
AIRPORT (AIRPORT_CODE) );
CREATE TABLE AIRPLANE ( AIRPLANE_ID INTEGER NOT NULL,
TOTAL_NUMBER_OF_SEATS INTEGER NOT NULL,
AIRPLANE_TYPE VARCHAR(20) NOT NULL,
PRIMARY KEY (AIRPLANE_ID),
FOREIGN KEY (AIRPLANE_TYPE) REFERENCES AIRPLANE_TYPE (TYPE_NAME) );
CREATE TABLE SEAT_RESERVATION ( FLIGHT_NUMBER VARCHAR(6) NOT NULL,
LEG_NUMBER INTEGER NOT NULL,
LEG_DATE DATE NOT NULL,
SEAT_NUMBER VARCHAR(4),
CUSTOMER_NAME VARCHAR(30) NOT NULL,
CUSTOMER_PHONE CHAR(12),
PRIMARY KEY (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE, SEAT_NUMBER),
FOREIGN KEY (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE) REFERENCES
LEG_INSTANCE (FLIGHT_NUMBER, LEG_NUMBER, LEG_DATE) );
3
  Consider the LIBRARY relational database schema of Figure 4.6. Choose the appropriate action (reject, cascade, set to null, set to default) for each referential integrity constraint, both for the deletion of a referenced tuple, and for the update of a primary key attribute value in a referenced tuple. Justify your choices.
Consider the LIBRARY relational database schema of Figure 4.6. Choose the appropriate action (reject, cascade, set to null, set to default) for each referential integrity constraint, both for the deletion of a referenced tuple, and for the update of a primary key attribute value in a referenced tuple. Justify your choices.
Below are possible choices. In general, if it is not clear which action to choose, REJECT should be chosen, since it will not permit automatic changes to happen (by update propagation) that may be unintended.
BOOK_AUTHORS.(BookId) -- > BOOK.(BookId)
CASCADE on both DELETE or UPDATE (since this corresponds to a multi-valued attribute of BOOK (see the solution to Exercise 6.27); hence, if a BOOK is deleted, or the value of its BookId is updated (changed), the deletion or change is automatically propagated to the referencing BOOK_AUTHORS tuples) BOOK.(PublisherName) -- > PUBLISHER.(Name) REJECT on DELETE (we should not delete a PUBLISHER tuple which has existing BOOK tuples that reference the PUBLISHER) CASCADE on UPDATE (if a PUBLISHER's Name is updated, the change should be propagated automatically to all referencing BOOK tuples)
BOOK_LOANS.(BookId) -- > BOOK.(BookId)
CASCADE on both DELETE or UPDATE (if a BOOK is deleted, or the value of its BookId is updated (changed), the deletion or change is automatically propagated to the referencing BOOK_LOANS tuples) (Note: One could also choose REJECT on DELETE)
BOOK_COPIES.(BookId) -- > BOOK.(BookId)
CASCADE on both DELETE or UPDATE (if a BOOK is deleted, or the value of its BookId is updated (changed), the deletion or change is automatically propagated to the referencing BOOK_COPIES tuples)
BOOK_LOANS.(CardNo) -- > BORROWER.(CardNo)
CASCADE on both DELETE or UPDATE (if a BORROWER tuple is deleted, or the value of its CardNo is updated (changed), the deletion or change is automatically propagated to the
referencing BOOK_LOANS tuples) (Note: One could also choose REJECT on DELETE, with the idea that if a BORROWER is deleted, it is necessary first to make a printout of all BOOK_LOANS outstanding before deleting the BORROWER; in this case, the tuples in BOOK_LOANS that reference the BORROWER being deleted would first be explicitly deleted after making the printout, and before the BORROWER is deleted)
BOOK_COPIES.(BranchId) -- > LIBRARY_BRANCH.(BranchId) CASCADE on both DELETE or UPDATE (if a LIBRARY_BRANCH is deleted, or the value of its BranchId is updated (changed), the deletion or change is automatically propagated to the referencing BOOK_COPIES tuples) (Note: One could also choose REJECT on DELETE)
BOOK_LOANS.(BranchId) -- > LIBRARY_BRANCH.(BranchId)
CASCADE on both DELETE or UPDATE (if a LIBRARY_BRANCH is deleted, or the value of its BranchId is updated (changed), the deletion or change is automatically propagated to the referencing BOOK_LOANS tuples) (Note: One could also choose REJECT on DELETE)
4
  Write appropriate SQL DDL statements for declaring the LIBRARY relational database schema of Figure 4.6. Specify the keys and referential triggered actions.
Write appropriate SQL DDL statements for declaring the LIBRARY relational database schema of Figure 4.6. Specify the keys and referential triggered actions.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
5
How can the key and foreign key constraints be enforced by the DBMS? Is the enforcement technique you suggest difficult to implement? Can the constraint checks be executed in an efficient manner when updates are applied to the database?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
6
Exercise 3.11
Suppose that each of the following Update operations is applied directly to
the database state shown in Figure 3.6.
Exercise 3.11 Suppose that each of the following Update operations is applied directly to the database state shown in Figure 3.6.   Discuss all integrity constraints violated by each operation, if any, and the different ways of enforcing these constraints. a. Insert <'Robert', 'F', 'Scott', '943775543', '1972-06-21', '2365 Newcastle Rd, Bellaire, TX', M, 58000, '888665555', 1> into EMPLOYEE. b. Insert <'ProductA', 4, 'Bellaire', 2> into PROJECT. c. Insert <'Production', 4, '943775543', '2007-10-01'> into DEPARTMENT. d. Insert <'677678989', NULL, '40.0'> into WORKS_ON. e. Insert <'453453453', 'John', 'M', '1990-12-12', 'spouse'> into DEPENDENT. f. Delete the WORKS_ON tuples with Essn = '333445555'. g. Delete the EMPLOYEE tuple with Ssn = '987654321'. h. Delete the PROJECT tuple with Pname = 'ProductX'. i. Modify the Mgr_ssn and Mgr_start_date of the DEPARTMENT tuple with Dnumber = 5 to '123456789' and '2007-10-01', respectively. j. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn = '999887777' to '943775543'. k. Modify the Hours attribute of the WORKS_ON tuple with Essn = '999887777' and Pno = 10 to '5.0'. Specify the updates of Exercise 3.11 using the SQL update commands. Discuss all integrity constraints violated by each operation, if any, and the different ways of enforcing these constraints.
a. Insert <'Robert', 'F', 'Scott', '943775543', '1972-06-21', '2365 Newcastle Rd,
Bellaire, TX', M, 58000, '888665555', 1> into EMPLOYEE.
b. Insert <'ProductA', 4, 'Bellaire', 2> into PROJECT.
c. Insert <'Production', 4, '943775543', '2007-10-01'> into DEPARTMENT.
d. Insert <'677678989', NULL, '40.0'> into WORKS_ON.
e. Insert <'453453453', 'John', 'M', '1990-12-12', 'spouse'> into DEPENDENT.
f. Delete the WORKS_ON tuples with Essn = '333445555'.
g. Delete the EMPLOYEE tuple with Ssn = '987654321'.
h. Delete the PROJECT tuple with Pname = 'ProductX'.
i. Modify the Mgr_ssn and Mgr_start_date of the DEPARTMENT tuple with
Dnumber = 5 to '123456789' and '2007-10-01', respectively.
j. Modify the Super_ssn attribute of the EMPLOYEE tuple with Ssn =
'999887777' to '943775543'.
k. Modify the Hours attribute of the WORKS_ON tuple with Essn =
'999887777' and Pno = 10 to '5.0'.
Specify the updates of Exercise 3.11 using the SQL update commands.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
7
  Specify the following queries in SQL on the database schema of Figure 1.2. (a) Retrieve the names of all senior students majoring in 'COSC' (computer science). (b) Retrieve the names of all courses taught by professor King in 85 and 86. (c) For each section taught by professor King, retrieve the course number, semester, year, and number of students who took the section. (d) Retrieve the name and transcript of each senior student (Class=5) majoring in COSC. Transcript includes course name, course number, credit hours, semester, year, and grade for each course completed by the student. (e) Retrieve the names and major departments of all straight A students (students who have a grade of A in all their courses). (f) Retrieve the names and major departments of all students who do not have any grade of A in any of their courses.
Specify the following queries in SQL on the database schema of Figure 1.2.
(a) Retrieve the names of all senior students majoring in 'COSC' (computer science).
(b) Retrieve the names of all courses taught by professor King in 85 and 86.
(c) For each section taught by professor King, retrieve the course number, semester, year, and number of students who took the section.
(d) Retrieve the name and transcript of each senior student (Class=5) majoring in COSC. Transcript includes course name, course number, credit hours, semester, year, and grade for each course completed by the student.
(e) Retrieve the names and major departments of all straight A students (students who have a grade of A in all their courses).
(f) Retrieve the names and major departments of all students who do not have any grade of A in any of their courses.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
8
  Write SQL update statements to do the following on the database schema shown in Figure 1.2. (a) Insert a new student < 'Johnson', 25, 1, 'MATH' > in the database. (b) Change the class of student 'Smith' to 2. (c) Insert a new course < 'Knowledge Engineering','COSC4390', 3,'COSC' > . (d) Delete the record for the student whose name is 'Smith' and student number is 17.
Write SQL update statements to do the following on the database schema shown in Figure 1.2.
(a) Insert a new student < 'Johnson', 25, 1, 'MATH' > in the database.
(b) Change the class of student 'Smith' to 2.
(c) Insert a new course < 'Knowledge Engineering','COSC4390', 3,'COSC' > .
(d) Delete the record for the student whose name is 'Smith' and student number is 17.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
9
     Consider the EMPLOYEE table's constraint EMPSUPERFK as specified in Figure 4.2 is changed to read as follows: CONSTRAINT EMPSUPERFK FOREIGN KEY (SUPERSSN) REFERNCES EMPLOYEE(SSN) ON DELETE CASCADE ON UPDATE CASCADE, Answer the following questions: a. What happens when the following command is run on the database state shown in Figure 3.6? DELETE EMPLOYEE WHERE LNAME = 'Borg' b. Is it better to CASCADE or SET NULL in case of EMPSUPERFK constraint ON DELETE?

     Consider the EMPLOYEE table's constraint EMPSUPERFK as specified in Figure 4.2 is changed to read as follows: CONSTRAINT EMPSUPERFK FOREIGN KEY (SUPERSSN) REFERNCES EMPLOYEE(SSN) ON DELETE CASCADE ON UPDATE CASCADE, Answer the following questions: a. What happens when the following command is run on the database state shown in Figure 3.6? DELETE EMPLOYEE WHERE LNAME = 'Borg' b. Is it better to CASCADE or SET NULL in case of EMPSUPERFK constraint ON DELETE?
Consider the EMPLOYEE table's constraint EMPSUPERFK as specified in Figure 4.2 is changed to read as follows: CONSTRAINT EMPSUPERFK FOREIGN KEY (SUPERSSN) REFERNCES EMPLOYEE(SSN) ON DELETE CASCADE ON UPDATE CASCADE, Answer the following questions:
a. What happens when the following command is run on the database state shown in Figure 3.6?
DELETE EMPLOYEE WHERE LNAME = 'Borg'
b. Is it better to CASCADE or SET NULL in case of EMPSUPERFK constraint ON DELETE?
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
10
  Write SQL statements to create a table EMPLOYEE_BACKUP backup of EMPLOYEE table shown in Figure 3.6.
Write SQL statements to create a table EMPLOYEE_BACKUP backup of EMPLOYEE table shown in Figure 3.6.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 10 في هذه المجموعة.