SQL Query Practice: Finding Courses in Multiple Semesters
30 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

In SQL, what does using a select statement in an insert query do?

  • Includes rows resulting from the selection in the insertion (correct)
  • Deletes rows selected by the query
  • Inserts the selected rows into the table
  • Updates the rows based on the select statement
  • Which SQL query deletes all tuples in the 'instructor' relation for instructors associated with a department located in the Watson building from the 'department' relation?

  • DELETE FROM department WHERE building='Watson';
  • DELETE FROM instructor WHERE dept_name IN (SELECT dept_name FROM department WHERE building = 'Watson'); (correct)
  • None of the mentioned
  • DELETE FROM instructor WHERE dept_name IN 'Watson';
  • What keyword is used to update a specific attribute in a SQL update statement?

  • Select
  • Set (correct)
  • In
  • Where
  • In SQL update statements, what is useful in the set clause?

    <p>Scalar subqueries</p> Signup and view all the answers

    How is the problem of ordering updates in multiple updates avoided in SQL?

    <p>Case</p> Signup and view all the answers

    What is the correct format for SQL case statements?

    <p>CASE WHEN pred1...result1 WHEN pred2...result2...WHEN predn...</p> Signup and view all the answers

    What is the purpose of the EXISTS keyword in SQL?

    <p>Checking if any row in the subquery meets the condition</p> Signup and view all the answers

    Which SQL keyword is used to create a temporary relation?

    <p>With</p> Signup and view all the answers

    When using SQL, how can you identify rows that do not meet a specified condition?

    <p>Applying NOT EXISTS twice</p> Signup and view all the answers

    In SQL, which keyword will be true if all rows in the subquery fail to meet a certain condition?

    <p>All rows in the subquery fail the condition only</p> Signup and view all the answers

    Which option correctly describes the purpose of the MIN function in SQL?

    <p>Finding the minimum value in a column</p> Signup and view all the answers

    What is the main distinction between using AND and OR operators in SQL queries?

    <p>AND operator requires both conditions to be true, while OR requires either one to be true.</p> Signup and view all the answers

    What should be done to avoid cascading of authorizations from the user?

    <p>Revoke select on department from Amit, Satoshi restrict</p> Signup and view all the answers

    How can user role confusions be avoided when roles are revoked?

    <p>The privilege must be granted only by roles</p> Signup and view all the answers

    What is the purpose of executing 'set role name' in a session?

    <p>To set a new role for the session</p> Signup and view all the answers

    Which keyword can be used to indicate that revocation should cascade?

    <p>cascade</p> Signup and view all the answers

    How does revoking with 'restrict' differ from 'cascade'?

    <p>'Restrict' prevents cascading revocation</p> Signup and view all the answers

    What happens if a specified role has not been granted to the user when using 'set role name'?

    <p>'set role name' fails</p> Signup and view all the answers

    What type of query language is Relational Algebra?

    <p>Procedural</p> Signup and view all the answers

    Which of the following operations is NOT a fundamental operation in relational algebra?

    <p>None of the mentioned</p> Signup and view all the answers

    How is the selection operation denoted in relational algebra?

    <p>Sigma (Greek)</p> Signup and view all the answers

    In the select operation of relational algebra, where do predicates appear?

    <p>Predicates, relation</p> Signup and view all the answers

    Which of the following is NOT a fundamental operation in relational algebra?

    <p>Natural join</p> Signup and view all the answers

    What does the relational algebra operation 'rename' do?

    <p>Change the name of a relation</p> Signup and view all the answers

    Which SQL query is used to find all courses taught in both the Fall 2009 semester and in the Spring 2010 semester?

    <p>SELECT course id FROM SECTION AS S WHERE semester = ’Fall’ AND YEAR= 2009 AND EXISTS (SELECT * FROM SECTION AS T WHERE semester = ’Spring’ AND YEAR= 2010 AND S.course id= T.course id);</p> Signup and view all the answers

    Which SQL construct is used to test for the nonexistence of tuples in a subquery?

    <p>Not exists</p> Signup and view all the answers

    What does the SQL query 'SELECT COUNT(DISTINCT ID) FROM takes WHERE (course id, sec id, semester, YEAR) IN (SELECT course id, sec id, semester, YEAR FROM teaches WHERE teaches.ID= 10101);' primarily aim to do?

    <p>Retrieve the distinct ID count from the 'takes' table based on certain conditions.</p> Signup and view all the answers

    In the context of database management systems, what does the SQL 'salary > SOME (SELECT salary FROM instructor WHERE dept name = ’Biology’)' query mainly focus on?

    <p>Selecting salaries greater than any salary in the Biology department.</p> Signup and view all the answers

    Which SQL query is used to find courses taught in the Spring 2010 semester?

    <p>(SELECT course id FROM SECTION WHERE semester = ’Spring’ AND YEAR= 2010)</p> Signup and view all the answers

    What is the primary purpose of using 'Exists' in an SQL query?

    <p>To check for nonexistence of tuples.</p> Signup and view all the answers

    More Like This

    SQL Database Concepts Quiz
    5 questions

    SQL Database Concepts Quiz

    UndisputedChalcedony4145 avatar
    UndisputedChalcedony4145
    SQL Query Writing
    4 questions

    SQL Query Writing

    MercifulAbundance avatar
    MercifulAbundance
    Introduction to SQL Query Optimization
    13 questions
    Use Quizgecko on...
    Browser
    Browser