DSAD based on lecture notes

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

How do nested queries enhance SQL's capabilities?

  • They enable you to embed a `SELECT` statement within another SQL statement, leveraging the results of one query in another. (correct)
  • They are primarily used for deleting records from a database table.
  • They provide a mechanism to define new tables within a database.
  • They offer enhanced sorting functionalities compared to standard `ORDER BY` clauses.

Which SQL operator is best suited for verifying if a specific value exists within the result set of a subquery that returns a single column?

  • `COUNT`
  • `IN` (correct)
  • `AVG`
  • `EXISTS`

When implementing nested queries, what is a potential performance pitfall to be aware of?

  • Nested queries can sometimes lead to inefficiencies because the database system might process them like nested loops. (correct)
  • Nested queries are generally more efficient than using joins, especially for large datasets.
  • Nested queries can only be used when querying a single table, restricting their applicability in multi-table scenarios.
  • Nested queries are incompatible with aggregation functions, limiting their use in complex queries.

Which SQL keyword can you use to eliminate duplicate rows from the output of a SELECT query?

<p><code>DISTINCT</code> (D)</p> Signup and view all the answers

What is the fundamental role of SQL in database management?

<p>It provides a standard language for interacting with and managing relational databases. (C)</p> Signup and view all the answers

What is the direct consequence of excluding a connecting condition when joining tables in a SELECT query?

<p>The query will generate a cross product of the tables involved, potentially yielding a large number of unintended combinations. (A)</p> Signup and view all the answers

Who is recognized as the originator of relational databases?

<p>Edgar Codd (B)</p> Signup and view all the answers

Which SQL clause is used to apply conditions to groups created by the GROUP BY clause?

<p><code>HAVING</code> (D)</p> Signup and view all the answers

In SQL, what is the role of the EXCEPT operator?

<p>It returns rows from the first query's result that are not present in the second query's result. (C)</p> Signup and view all the answers

How do aggregate functions like COUNT handle NULL values in SQL?

<p><code>NULL</code> values are automatically excluded from the aggregation. (D)</p> Signup and view all the answers

Within an Entity-Relationship (ER) model, what does an entity signify?

<p>An entity models a real-world object or concept about which data is stored. (D)</p> Signup and view all the answers

In an Entity-Relationship (ER) diagram, what does a multiplicity of (0,1) on a relationship indicate?

<p>The relationship can have either zero or one instance. (B)</p> Signup and view all the answers

Which SQL constraint is used to enforce that a particular column cannot contain NULL values?

<p><code>NOT NULL</code> (C)</p> Signup and view all the answers

Which relational algebra operation is used to select a subset of rows from a table based on a specified condition?

<p>Selection (A)</p> Signup and view all the answers

What is the worst-case time complexity of performing a Natural Join operation between two tables?

<p>O(n²) (B)</p> Signup and view all the answers

What is the primary function of the Rename operator (ρ) in relational algebra?

<p>To change the name of a table or the attributes within a table. (B)</p> Signup and view all the answers

Under which specific condition can a relationship table be effectively merged into one of the entity tables involved in the relationship?

<p>When the multiplicity of the relationship is either (0,1) or (1,1). (C)</p> Signup and view all the answers

In SQL, what is the purpose of the REFERENCES constraint when defining a foreign key?

<p>It establishes a link between the foreign key in one table and the primary key in another table. (B)</p> Signup and view all the answers

What does ON DELETE CASCADE signify when configured as part of a foreign key constraint in SQL?

<p>It automatically deletes the records in the child table that reference the record being deleted in the parent table. (D)</p> Signup and view all the answers

What is the defining characteristic of a weak entity in an Entity-Relationship (ER) model?

<p>A weak entity is an entity whose existence depends on another entity, and it does not have a primary key of its own. (D)</p> Signup and view all the answers

In the context of Entity-Relationship (ER) modeling, what does a (t, e) annotation on a hierarchy indicate about the coverage and overlap of subclasses?

<p>Total coverage, exclusive subclasses. (D)</p> Signup and view all the answers

Which of the following examples represents an attribute within the specific context of the library ER model?

<p>Title (D)</p> Signup and view all the answers

Which SQL clause is used to sort the result set of a query?

<p>ORDER BY (B)</p> Signup and view all the answers

What does the term 'cardinality' refer to in the context of database relationships?

<p>The maximum number of relationships that can exist between entities. (B)</p> Signup and view all the answers

What is the purpose of normalization in database design?

<p>To organize data efficiently, reduce redundancy, and eliminate update anomalies. (A)</p> Signup and view all the answers

In terms of database transactions, what does the acronym ACID stand for?

<p>Atomicity, Consistency, Isolation, Durability (B)</p> Signup and view all the answers

Which SQL command is used to modify the structure of an existing table?

<p>ALTER (C)</p> Signup and view all the answers

What is the purpose of creating an index on a database column?

<p>To improve the speed of data retrieval operations. (D)</p> Signup and view all the answers

What is a stored procedure in SQL?

<p>A set of SQL statements that are stored and executed as a unit. (B)</p> Signup and view all the answers

What is the role of a database trigger?

<p>To execute a set of SQL statements in response to a specific event. (B)</p> Signup and view all the answers

Flashcards

What is a nested query?

Uses a SELECT query within another query.

What does the IN operator do?

Checks if a value exists in a subquery's result.

What's a downside of nested queries?

Can be inefficient due to nested loop behavior.

What does DISTINCT do?

Removes duplicate rows from a query result.

Signup and view all the flashcards

What does SQL stand for?

Structured Query Language.

Signup and view all the flashcards

What happens without a JOIN condition?

Creates a cross product, yielding many unwanted results.

Signup and view all the flashcards

Who invented relational databases?

Edgar Codd

Signup and view all the flashcards

What does HAVING do in SQL?

Filters groups after aggregation.

Signup and view all the flashcards

What does EXCEPT do?

Returns results from the first query that are NOT in the second.

Signup and view all the flashcards

How are NULLs handled in COUNT?

NULL values are skipped in functions like COUNT.

Signup and view all the flashcards

What is an entity?

Represents a real-world object or concept.

Signup and view all the flashcards

What does (0,1) multiplicity mean?

Zero or one occurrence.

Signup and view all the flashcards

What does NOT NULL do?

Ensures a field cannot be NULL.

Signup and view all the flashcards

What does selection do?

Filters rows based on a condition.

Signup and view all the flashcards

What does Rename (ρ) do?

Changes the name of a table or attribute.

Signup and view all the flashcards

Purpose of decomposition?

Splits a big table to remove unwanted dependencies.

Signup and view all the flashcards

What does REFERENCES do?

Links a foreign key to a primary key.

Signup and view all the flashcards

What is ON DELETE CASCADE?

Deletes FK records when the referenced record is deleted.

Signup and view all the flashcards

What is a weak entity?

Depends on another entity for its identity.

Signup and view all the flashcards

What is a hierarchy?

A subclass (is a) of a superclass.

Signup and view all the flashcards

What is a (t,e) annotation?

Total coverage and exclusive subclasses.

Signup and view all the flashcards

What is Title?

An attribute in the library ER model.

Signup and view all the flashcards

Purpose of a primary key?

A primary key uniquely identifies each record.

Signup and view all the flashcards

What is a relationship?

Connects entities, describing how they interact.

Signup and view all the flashcards

What is a functional dependency??

Functional dependency means one attribute determines another.

Signup and view all the flashcards

Study Notes

Quiz 1: Week 5, Lecture 1 - Nested Queries (SQL)

  • A nested query is a SELECT query within another query.
  • Nested queries can be inefficient, acting like nested loops.
  • DISTINCT removes duplicate records from a query result.
  • The IN operator checks if a value exists in a single-column table returned by a subquery.
  • SQL query to find course names that have no marks in the allmarks table: SELECT name FROM course WHERE bc NOT IN (SELECT bc FROM allmarks);
  • The EXISTS operator can be useful to check if a subquery returns any records.
  • Rewriting SELECT name FROM course WHERE bc IN (SELECT bc FROM allmarks); without a subquery: SELECT DISTINCT name FROM course, allmarks WHERE course.bc = allmarks.bc;

Quiz 2: Week 4, Lecture 1 - Intro & Queries (SQL)

  • SQL stands for Structured Query Language.
  • Omitting a connecting condition when joining multiple tables can result in a cross product.
  • Edgar Codd invented relational databases.
  • SQL query to find the course names and years taught by a staff member with the last name 'Reddy': SELECT name, year FROM staff, lecturing, course WHERE staff.lastname = 'Reddy' AND staff.sid = lecturing.sid AND lecturing.cid = course.cid;
  • DISTINCT removes duplicate rows from the result set of a query.
  • A schema summarizes the structure of a database, defining the tables and their columns.

Quiz 3: Week 4, Lecture 2 - More Queries (SQL)

  • The HAVING clause filters groups after aggregation.
  • The EXCEPT operator returns results from the first query not in the second.
  • NULL values are skipped in aggregation operations like COUNT.
  • SQL query to find courses with no hard-failing students (marks < 40): (SELECT bc FROM allmarks) EXCEPT (SELECT bc FROM allmarks WHERE mark < 40);
  • WHERE filters individual rows before aggregation.
  • HAVING filters groups after aggregation based on functions like COUNT or AVG.
  • SQL query to count distinct courses taught each year: SELECT year, COUNT(DISTINCT cid) FROM lecturing GROUP BY year;

Quiz 4: Week 7, Lecture 1 - Entity-Relationship Concepts

  • In an ER model, an entity represents a "thing" with data to be stored.
  • A multiplicity of (0,1) indicates zero or one occurrence is allowed in a relationship.
  • The NOT NULL keyword ensures a field cannot be NULL.
  • Schema for a Borrow table based on the small library ER model: Borrow(book_id, member_num, date, due_date, return_date, fine)
  • A primary key uniquely identifies each record in a table.
  • A relationship connects entities, describing how they interact (e.g., "borrowed" between Book and Member).

Quiz 5: Week 5, Lecture 2 - Relational Algebra

  • The Selection operation filters rows based on a condition.
  • The worst-case time complexity of a Natural Join is O(n²).
  • The Rename operator (ρ) changes the name of a table or its attributes.
  • Relational algebra expression to find employees in the Finance department: σ_{Dept='Finance'}(Employee)
  • A functional dependency means one attribute determines another (e.g., empID → Name).
  • Decomposition splits a large table into smaller ones to eliminate unwanted functional dependencies.

Quiz 6: Week 8, Lecture 1 - Logical Design: Deriving Tables from E-R Models

  • A relationship table can be merged into an entity table when the multiplicity is (0,1) or (1,1).
  • The REFERENCES constraint links a foreign key to a primary key in another table.
  • ON DELETE CASCADE deletes records with foreign keys when the referenced record is deleted.
  • Optimized schema for the Member table including Borrow fields from the library example: Member(member_num, last_name, first_name, address, date_of_joining, book_id°, borrow_date°, due_date°, return_date°, fine°)
  • Three tables (Member, Book, Borrow) avoid NULL values, handle multiple borrowings better and reduce redundancy.
  • A foreign key references a primary key in another table (e.g., book_id in Borrow references book_id in Book).

Quiz 7: Week 7, Lecture 2 - Entity-Relationship Modeling

  • A weak entity depends on another for its identity.
  • A (t, e) annotation on a hierarchy means total coverage and exclusive subclasses.
  • Title is an attribute in the library ER model.
  • Schema for the Copy table in the revised library ER model: Copy(book_id, copy_num)
  • A strong entity has its own unique primary key.
  • A weak entity relies on another entity’s key plus additional attributes for its identity.
  • A hierarchy represents an "is-a" relationship where subclasses inherit from a superclass (e.g., UG_student and PG_student being subclasses of Student).

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team
Use Quizgecko on...
Browser
Browser