duminică, 4 aprilie 2010

Test: Quiz: Updating Column Values and Deleting Rows

Section 1

1. How many rows will be deleted from the employees table with the following statement?

DELETE FROM employees
WHERE last_name = 'king';
Mark for Review
(1) Points


All the rows in the employees table will be deleted.


No rows will be deleted, as no employees match the WHERE-clause. (*)


One will be deleted, as there exists one employee called King.


All rows with last_name = 'King' will be deleted.






2. To change an existing row in a table, you can use the UPDATE or INSERT statements. True or False? Mark for Review
(1) Points


True


False (*)






3. Assuming there are no Foreign Keys on the EMPLOYEES table, if the following subquery returns one row, how many rows will be deleted from the EMPLOYEES table?

DELETE FROM employees
WHERE department_id =
(SELECT department_id
FROM departments
WHERE department_name LIKE '%Public%');

Mark for Review
(1) Points


No rows will be deleted.


One row will be deleted, as the subquery only returns one row.


All the rows in the EMPLOYEES table with department_ids matching the department_id returned by the subquery. (*)


All rows in the EMPLOYEES table will be deleted, regardless of their department_id.






4. DELETE statements can use correlated subqueries? (True or False) Mark for Review
(1) Points


True (*)


False


5. Is the following statement valid, i.e. is it allowed to update rows in one table, based on a subquery from another table?

UPDATE copy_emp
SET department_id = (SELECT department_id
FROM employees
WHERE employee_id = 100)
WHERE job_id = (SELECT job_id
FROM employees
WHERE employee_id = 200);

Mark for Review
(1) Points


Yes, this is a perfectly valid statement. (*)


The statement will fail, because the subqueries are returning data from different rows


No, this will not work


No, this statement will return an error.






6. Using your knowledge of the employees table, what would be the result of the following statement:
DELETE FROM employees;

Mark for Review
(1) Points


Nothing, no data will be changed.


All rows in the employees table will be deleted if there are no constraints on the table. (*)


The first row in the employees table will be deleted.


Deletes employee number 100.






7. If the subquery returns one row, how many rows will be deleted from the employees table?

DELETE FROM employees
WHERE department_id =
(SELECT department_id
&nbspFROM departments
&nbspWHERE department_name LIKE '%Public%');
Mark for Review
(1) Points


No rows will be deleted.


One row will be deleted, as the subquery only returns one row.


All rows in the employees table which work in the given department will be deleted. (*)


All rows in the employees table will be deleted, no matter their department_id.


8. If you are performing an UPDATE statement with a subquery, it MUST be a correlated subquery? (True or False) Mark for Review
(1) Points


True


False (*)


9. Which of the following statements best describes what will happen to the student table in this SQL statement?

UPDATE students
SET lunch_number =
(SELECT lunch_number
FROM student
WHERE student_id = 17)
WHERE student_id = 19;

Mark for Review
(1) Points


The statement updates the student_table by replacing student id 19's lunch number with student id 17's lunch number. (*)


Inserts a new row into the students table.


Does nothing, the as you cannot use subqueries in update statements.


Deletes student 17's lunch_number and inserts a new value from student 19.
http://www.materie.ro/materie/test-quiz-updating-column-values-and-deleting-rows-37

Niciun comentariu:

Trimiteţi un comentariu