1. Home
  2. Explore
  3. Computer Science
  4. SQL Database Course

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

SQL Database Course

  • 32Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Database Fundamentals

What is a database in the most general sense?

32 questions

  1. 1

    What is a database in the most general sense?

    1. A

      Any collection of related information, regardless of storage medium

    2. B

      A structured set of data managed by a DBMS

    3. C

      A software application for creating and managing data

    4. D

      Any collection of related information stored on a computer

    Correct answer
    A

    Any collection of related information, regardless of storage medium

    Explanation

    The most general definition of a database is any collection of related information, which can be stored on paper, in memory, or on a computer.

  2. 2

    What does CRUD stand for?

    1. A

      Create, Read, Update, Drop

    2. B

      Create, Read, Update, Delete

    3. C

      Create, Retrieve, Update, Drop

    4. D

      Create, Retrieve, Update, Delete

    Correct answer
    B

    Create, Read, Update, Delete

    Explanation

    CRUD stands for Create, Read, Update, and Delete. Sometimes 'Retrieve' is used instead of 'Read', but the standard acronym is Create, Read, Update, Delete.

  3. 3

    Which type of database organizes data into tables with rows and columns?

    1. A

      Document database

    2. B

      Graph database

    3. C

      Relational database

    4. D

      Non-relational database

    Correct answer
    C

    Relational database

    Explanation

    Relational databases organize data into tables (relations) with rows and columns, unlike non-relational databases which use other structures.

  4. 4

    What is a primary key?

    1. A

      An attribute that stores a default value

    2. B

      An attribute that uniquely identifies each row and cannot be NULL

    3. C

      An attribute that links two tables together

    4. D

      An attribute that can be NULL and must be unique

    Correct answer
    B

    An attribute that uniquely identifies each row and cannot be NULL

    Explanation

    A primary key is an attribute (or set of attributes) that uniquely identifies each row in a table. It must be unique and cannot contain NULL values.

  5. 5

    Which type of primary key has no mapping to anything in the real world?

    1. A

      Composite key

    2. B

      Surrogate key

    3. C

      Foreign key

    4. D

      Natural key

    Correct answer
    B

    Surrogate key

    Explanation

    A surrogate key is a primary key that has no real-world meaning, such as an auto-incrementing integer. A natural key has a real-world mapping, like a Social Security Number.

  6. 6

    What is a foreign key?

    1. A

      An attribute that cannot have duplicate values

    2. B

      An attribute that automatically increments

    3. C

      An attribute that stores the primary key of another table to define a relationship

    4. D

      An attribute that is always part of the primary key

    Correct answer
    C

    An attribute that stores the primary key of another table to define a relationship

    Explanation

    A foreign key is an attribute in a table that references the primary key of another table, establishing a relationship between the two tables.

  7. 7

    What is a composite key?

    1. A

      A foreign key that references multiple tables

    2. B

      A key that uses a combination of surrogate and natural keys

    3. C

      A primary key that consists of two or more columns

    4. D

      A key that is both primary and foreign

    Correct answer
    C

    A primary key that consists of two or more columns

    Explanation

    A composite key (or compound key) is a primary key made up of two or more columns. Together, these columns uniquely identify each row.

  8. 8

    What does SQL stand for?

    1. A

      Standard Query Language

    2. B

      Sequential Query Language

    3. C

      Structured Query Language

    4. D

      Simple Query Language

    Correct answer
    C

    Structured Query Language

    Explanation

    SQL stands for Structured Query Language. It is a standardized language for interacting with relational database management systems.

  9. 9

    Which of the following is NOT a category of SQL?

    1. A

      Data Control Language (DCL)

    2. B

      Data Integration Language (DIL)

    3. C

      Data Query Language (DQL)

    4. D

      Data Definition Language (DDL)

    Correct answer
    B

    Data Integration Language (DIL)

    Explanation

    SQL is often divided into DQL (querying), DDL (defining schemas), DCL (access control), and DML (manipulating data). DIL is not a standard category.

  10. 10

    Which SQL data type is used to store binary large objects like images?

    1. A

      INT

    2. B

      DECIMAL

    3. C

      VARCHAR

    4. D

      BLOB

    Correct answer
    D

    BLOB

    Explanation

    BLOB (Binary Large Object) is used to store large amounts of binary data, such as images or files.

  11. 11

    What does the NOT NULL constraint do?

    1. A

      Automatically increments the column value

    2. B

      Sets a default value for a column

    3. C

      Ensures that a column cannot have duplicate values

    4. D

      Ensures that a column cannot contain NULL values

    Correct answer
    D

    Ensures that a column cannot contain NULL values

    Explanation

    NOT NULL ensures that a column must have a value; it cannot be left empty or contain NULL.

  12. 12

    What keyword is used to automatically generate sequential numbers for a column?

    1. A

      SEQUENCE

    2. B

      AUTO_INCREMENT

    3. C

      INCREMENT

    4. D

      AUTO_SEQUENCE

    Correct answer
    B

    AUTO_INCREMENT

    Explanation

    In MySQL, AUTO_INCREMENT is used to automatically generate unique numeric values for a column, typically for primary keys.

  13. 13

    Which statement is used to add a new row to a table?

    1. A

      INSERT INTO

    2. B

      CREATE

    3. C

      ADD INTO

    4. D

      UPDATE

    Correct answer
    A

    INSERT INTO

    Explanation

    INSERT INTO is used to add new rows (records) to a database table. UPDATE modifies existing rows, CREATE creates tables.

  14. 14

    What is the purpose of the WHERE clause in an UPDATE statement?

    1. A

      To specify which columns to update

    2. B

      To specify the new values for all rows

    3. C

      To sort the rows before updating

    4. D

      To specify which rows to update

    Correct answer
    D

    To specify which rows to update

    Explanation

    The WHERE clause in UPDATE filters which rows should be updated. Without it, all rows would be updated.

  15. 15

    What happens if you run a DELETE statement without a WHERE clause?

    1. A

      It deletes all rows in the table

    2. B

      It deletes the table structure

    3. C

      It returns an error

    4. D

      It deletes the first row only

    Correct answer
    A

    It deletes all rows in the table

    Explanation

    Without a WHERE clause, DELETE removes all rows from the table, leaving the table structure intact.

  16. 16

    Which SQL keyword is used to retrieve all columns from a table?

    1. A
    2. B

      ALL COLUMNS

    3. C

      EVERY

    4. D

      ALL

    Correct answer
    A

    Explanation

    The asterisk (*) is a wildcard that selects all columns in a table when used with SELECT.

  17. 17

    How do you sort results in descending order?

    1. A

      ORDER column DESC

    2. B

      ORDER BY column ASC

    3. C

      SORT BY column DESC

    4. D

      ORDER BY column DESC

    Correct answer
    D

    ORDER BY column DESC

    Explanation

    ORDER BY ... DESC sorts results in descending order. ASC (default) sorts ascending.

  18. 18

    Which clause limits the number of rows returned?

    1. A

      MAX

    2. B

      LIMIT

    3. C

      TOP

    4. D

      ROWNUM

    Correct answer
    B

    LIMIT

    Explanation

    LIMIT is used in MySQL to restrict the number of rows returned. Other databases may use TOP or ROWNUM.

  19. 19

    What does SELECT DISTINCT do?

    1. A

      Returns only unique values in the specified column

    2. B

      Returns the first distinct row

    3. C

      Returns all values including duplicates

    4. D

      Eliminates duplicate rows from the entire result set

    Correct answer
    A

    Returns only unique values in the specified column

    Explanation

    SELECT DISTINCT returns only distinct (different) values from a column, removing duplicates.

  20. 20

    Which SQL function counts the number of rows in a query?

    1. A

      SUM()

    2. B

      COUNT()

    3. C

      AVG()

    4. D

      TOTAL()

    Correct answer
    B

    COUNT()

    Explanation

    COUNT() returns the number of rows that match the query. SUM() adds values, AVG() averages them.

  21. 21

    What does GROUP BY do?

    1. A

      Groups rows that have the same values into summary rows

    2. B

      Filters rows based on a condition

    3. C

      Joins two tables together

    4. D

      Orders rows by a specified column

    Correct answer
    A

    Groups rows that have the same values into summary rows

    Explanation

    GROUP BY groups rows that have the same values in specified columns, often used with aggregate functions like COUNT or SUM.

  22. 22

    Which wildcard character represents any number of characters in SQL LIKE?

    1. A

      _

    2. B
    3. C

      %

    4. D

      ?

    Correct answer
    C

    %

    Explanation

    The percent sign (%) matches any sequence of zero or more characters. Underscore (_) matches exactly one character.

  23. 23

    What is the purpose of the UNION operator?

    1. A

      To insert multiple rows at once

    2. B

      To combine the results of two or more SELECT statements into a single result set

    3. C

      To join two tables based on a common column

    4. D

      To update rows from multiple tables

    Correct answer
    B

    To combine the results of two or more SELECT statements into a single result set

    Explanation

    UNION combines result sets from multiple SELECT queries into one. The SELECT statements must have the same number of columns and compatible data types.

  24. 24

    Which type of JOIN returns only rows where there is a match in both tables?

    1. A

      LEFT JOIN

    2. B

      FULL OUTER JOIN

    3. C

      INNER JOIN

    4. D

      RIGHT JOIN

    Correct answer
    C

    INNER JOIN

    Explanation

    INNER JOIN returns rows when there is at least one match in both tables. LEFT and RIGHT JOIN include non-matching rows from one side.

  25. 25

    In a LEFT JOIN, which table's rows are all included in the result?

    1. A

      The left table

    2. B

      The right table

    3. C

      Both tables

    4. D

      Neither table

    Correct answer
    A

    The left table

    Explanation

    LEFT JOIN includes all rows from the left table (the one specified in FROM), and matching rows from the right table. Non-matching rows have NULLs.

  26. 26

    What is a nested query?

    1. A

      A query that contains another query inside it

    2. B

      A query that joins multiple tables

    3. C

      A query that updates and deletes simultaneously

    4. D

      A query that uses aggregate functions

    Correct answer
    A

    A query that contains another query inside it

    Explanation

    A nested query (subquery) is a SELECT statement inside another SQL statement, often used in WHERE clauses to filter based on a subquery result.

  27. 27

    What does ON DELETE SET NULL do?

    1. A

      Sets the foreign key column to NULL when the referenced row is deleted

    2. B

      Deletes the row containing the foreign key

    3. C

      Cascades the deletion to related tables

    4. D

      Prevents deletion of the referenced row

    Correct answer
    A

    Sets the foreign key column to NULL when the referenced row is deleted

    Explanation

    ON DELETE SET NULL sets the foreign key column to NULL when the row it references is deleted. This is used when the foreign key is not part of the primary key.

  28. 28

    When must you use ON DELETE CASCADE instead of ON DELETE SET NULL?

    1. A

      When the foreign key is also part of the primary key

    2. B

      When the referenced table has a composite key

    3. C

      When the foreign key allows NULL values

    4. D

      When the foreign key is a surrogate key

    Correct answer
    A

    When the foreign key is also part of the primary key

    Explanation

    ON DELETE CASCADE is necessary when the foreign key is part of the primary key (or composite key), because a primary key cannot be NULL. The entire row must be deleted.

  29. 29

    What does a trigger in SQL do?

    1. A

      Generates random values for a column

    2. B

      Validates data before insertion

    3. C

      Automatically executes a set of SQL statements when a specified event occurs on a table

    4. D

      Creates a backup of the database

    Correct answer
    C

    Automatically executes a set of SQL statements when a specified event occurs on a table

    Explanation

    A trigger is a stored procedure that automatically runs when an INSERT, UPDATE, or DELETE operation occurs on a table. It can be set to run BEFORE or AFTER the event.

  30. 30

    What is the shape used to represent an entity in an ER diagram?

    1. A

      Diamond

    2. B

      Rectangle

    3. C

      Circle

    4. D

      Oval

    Correct answer
    B

    Rectangle

    Explanation

    In ER diagrams, entities are represented by rectangles. Attributes are ovals, and relationships are diamonds.

  31. 31

    How is a weak entity type represented in an ER diagram?

    1. A

      A single rectangle

    2. B

      A rectangle with double lines

    3. C

      A rectangle with an underline

    4. D

      A rectangle with dashed lines

    Correct answer
    B

    A rectangle with double lines

    Explanation

    A weak entity is shown as a double-lined rectangle. It cannot be uniquely identified by its own attributes alone; it depends on another entity.

  32. 32

    In converting a 1:N relationship to a schema, where should the foreign key be placed?

    1. A

      In the table on the '1' side

    2. B

      In a new table

    3. C

      In the table on the 'N' side

    4. D

      In both tables

    Correct answer
    C

    In the table on the 'N' side

    Explanation

    For a 1:N relationship, the primary key of the '1' side is added as a foreign key in the table on the 'N' side.

Question 1 of 32
Question 1 of 32

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent