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

Study methods

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

SQL Course Introduction

  • 37Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: SQL Fundamentals

What is a database management system (DBMS)?

37 questions

  1. 1

    What is a database management system (DBMS)?

    1. A

      A language used to query and modify data in relational databases

    2. B

      A software application used to manage databases and execute instructions

    3. C

      A collection of data stored in a format that can be easily accessed

    4. D

      A type of non-relational database that does not use tables

    Correct answer
    B

    A software application used to manage databases and execute instructions

    Explanation

    A DBMS is a software application that connects to databases, allows us to give instructions for querying or modifying data, and executes those instructions. It is not the data itself nor the language.

  2. 2

    What distinguishes relational databases from non-relational (NoSQL) databases?

    1. A

      Relational databases cannot handle large amounts of data, unlike NoSQL databases

    2. B

      Relational databases store data in tables linked by relationships, while NoSQL databases do not use tables or relationships

    3. C

      Relational databases use SQL exclusively, while NoSQL databases use a different query language called NoSQL

    4. D

      Relational databases are always open-source, while NoSQL databases are proprietary

    Correct answer
    B

    Relational databases store data in tables linked by relationships, while NoSQL databases do not use tables or relationships

    Explanation

    Relational databases store data in tables that are linked via relationships, which is why they are called relational. NoSQL databases do not have tables or relationships and have their own query languages.

  3. 3

    Why did SQL originally change its name from SEQUEL to SQL?

    1. A

      Because SEQUEL was a trademark of an airplane company

    2. B

      Because the developers wanted to align with other database languages

    3. C

      Because SQL is easier to pronounce than SEQUEL

    4. D

      Because SQL stands for Structured Query Language, which is more descriptive

    Correct answer
    A

    Because SEQUEL was a trademark of an airplane company

    Explanation

    SQL was originally called SEQUEL (Structured English Query Language) but was changed to SQL because SEQUEL was a trademark of an airplane company.

  4. 4

    In MySQL Workbench, what does the 'Schemas' tab display?

    1. A

      The databases available in the current database server

    2. B

      The administrative tasks such as starting or stopping the server

    3. C

      The SQL query results and output messages

    4. D

      The list of stored procedures and functions

    Correct answer
    A

    The databases available in the current database server

    Explanation

    The Schemas tab shows the databases that exist in the current database server. The Administration tab is for administrative tasks.

  5. 5

    What is the default port for MySQL server?

    1. A

      3307

    2. B

      8080

    3. C

      3306

    4. D

      5432

    Correct answer
    C

    3306

    Explanation

    The default port for MySQL server is 3306, as stated in the content when configuring the connection.

  6. 6

    Which of the following is NOT a valid clause in a SQL SELECT statement?

    1. A

      HAVING

    2. B

      FROM

    3. C

      ORDER BY

    4. D

      WHERE

    Correct answer
    A

    HAVING

    Explanation

    HAVING is used with GROUP BY, not directly in a basic SELECT statement. The basic clauses are SELECT, FROM, WHERE, and ORDER BY.

  7. 7

    What is the purpose of the asterisk (*) in a SELECT statement?

    1. A

      It selects all rows from the table

    2. B

      It selects only the primary key column

    3. C

      It selects all columns from the specified table

    4. D

      It selects the first column of the table

    Correct answer
    C

    It selects all columns from the specified table

    Explanation

    The asterisk is a wildcard that returns all columns from the table. It is used to retrieve all columns without listing each one.

  8. 8

    How can you give a column a descriptive name in the result set?

    1. A

      By using the RENAME keyword

    2. B

      By using the ALIAS keyword

    3. C

      By using the AS keyword followed by an alias

    4. D

      By using the LABEL keyword

    Correct answer
    C

    By using the AS keyword followed by an alias

    Explanation

    The AS keyword is used to rename a column or expression in the result set. For example, 'SELECT points AS discount_factor'.

  9. 9

    Which operator is used to remove duplicate values from a result set?

    1. A

      DISTINCT

    2. B

      DIFFERENT

    3. C

      UNIQUE

    4. D

      REMOVE DUPLICATES

    Correct answer
    A

    DISTINCT

    Explanation

    The DISTINCT keyword is used in a SELECT clause to return only unique values, eliminating duplicates.

  10. 10

    What does the WHERE clause do in a SQL query?

    1. A

      It limits the number of rows returned

    2. B

      It filters rows based on a condition

    3. C

      It groups rows by a column

    4. D

      It sorts the result set

    Correct answer
    B

    It filters rows based on a condition

    Explanation

    The WHERE clause is used to filter records. Only rows that satisfy the condition are returned.

  11. 11

    Which comparison operator is used for 'not equal' in SQL?

    1. A

      Both != and <>

    2. B

      !=

    3. C

      <>

    4. D

      NOT EQUAL

    Correct answer
    A

    Both != and <>

    Explanation

    In SQL, both '!=' and '<>' are valid operators for 'not equal'. The content mentions both.

  12. 12

    How should date values be enclosed in SQL?

    1. A

      In single quotes

    2. B

      In parentheses

    3. C

      In double quotes only

    4. D

      In square brackets

    Correct answer
    A

    In single quotes

    Explanation

    Date values are enclosed in single quotes, even though they are not strings. The format is 'YYYY-MM-DD'.

  13. 13

    Which logical operator evaluates to true if both conditions are true?

    1. A

      AND

    2. B

      OR

    3. C

      NOT

    4. D

      XOR

    Correct answer
    A

    AND

    Explanation

    The AND operator returns true only when both conditions are true. OR returns true if at least one is true.

  14. 14

    What is the order of precedence for logical operators in SQL?

    1. A

      NOT, OR, AND

    2. B

      AND, OR, NOT

    3. C

      OR, AND, NOT

    4. D

      NOT, AND, OR

    Correct answer
    D

    NOT, AND, OR

    Explanation

    NOT has the highest precedence, followed by AND, then OR. Parentheses can override this order.

  15. 15

    Which operator is used to check if a value is within a list of values?

    1. A

      BETWEEN

    2. B

      IN

    3. C

      IS

    4. D

      LIKE

    Correct answer
    B

    IN

    Explanation

    The IN operator allows you to compare a column to a list of values. It is a shorter alternative to multiple OR conditions.

  16. 16

    What does the BETWEEN operator do?

    1. A

      It checks if a value is strictly greater than the lower bound and strictly less than the upper bound

    2. B

      It checks if a value is greater than or equal to the lower bound and less than or equal to the upper bound

    3. C

      It checks if a value is between two values exclusively

    4. D

      It checks if a value is equal to either the lower or upper bound only

    Correct answer
    B

    It checks if a value is greater than or equal to the lower bound and less than or equal to the upper bound

    Explanation

    BETWEEN is inclusive, meaning it includes the boundary values. For example, 'BETWEEN 1000 AND 3000' includes 1000 and 3000.

  17. 17

    In the LIKE operator, what does the percent sign (%) represent?

    1. A

      Exactly one character

    2. B

      Any single character

    3. C

      The beginning of a string

    4. D

      Any number of characters (including zero)

    Correct answer
    D

    Any number of characters (including zero)

    Explanation

    The percent sign (%) matches any sequence of characters (including an empty string). The underscore (_) matches a single character.

  18. 18

    What does the '^' character mean in a MySQL regular expression?

    1. A

      Logical OR

    2. B

      Any single character

    3. C

      End of string

    4. D

      Beginning of string

    Correct answer
    D

    Beginning of string

    Explanation

    The caret (^) in a regular expression denotes the start of a string. The dollar sign ($) denotes the end.

  19. 19

    How do you find rows where a column has no value (NULL)?

    1. A

      WHERE column EQUALS NULL

    2. B

      WHERE column == NULL

    3. C

      WHERE column = NULL

    4. D

      WHERE column IS NULL

    Correct answer
    D

    WHERE column IS NULL

    Explanation

    NULL is not a value, so you cannot use equality operators. Use 'IS NULL' to check for nulls. 'IS NOT NULL' checks for non-null values.

  20. 20

    What is the default sort order in an ORDER BY clause?

    1. A

      Random

    2. B

      Descending (DESC)

    3. C

      Alphabetical

    4. D

      Ascending (ASC)

    Correct answer
    D

    Ascending (ASC)

    Explanation

    The default sort order is ascending (ASC). You can specify DESC for descending order.

  21. 21

    Which clause is always placed at the end of a SELECT statement to limit the number of rows returned?

    1. A

      TOP

    2. B

      FETCH FIRST

    3. C

      ROWNUM

    4. D

      LIMIT

    Correct answer
    D

    LIMIT

    Explanation

    The LIMIT clause is used in MySQL to limit the number of rows. It must come after ORDER BY (if used).

  22. 22

    What does the following SQL statement do? SELECT * FROM orders LIMIT 6, 3

    1. A

      It returns the first 6 rows, then the next 3 rows

    2. B

      It returns 6 rows starting from row 3

    3. C

      It skips the first 6 rows and returns the next 3 rows

    4. D

      It returns rows 6 through 9

    Correct answer
    C

    It skips the first 6 rows and returns the next 3 rows

    Explanation

    In MySQL LIMIT, the first number is the offset (rows to skip), and the second is the number of rows to return. So LIMIT 6, 3 skips 6 and returns 3.

  23. 23

    When joining two tables with an INNER JOIN, what rows are included in the result?

    1. A

      All rows from the right table regardless of a match

    2. B

      All rows from both tables, with NULLs where there is no match

    3. C

      Only rows that have matching values in both tables

    4. D

      All rows from the left table regardless of a match

    Correct answer
    C

    Only rows that have matching values in both tables

    Explanation

    An INNER JOIN returns only rows where the join condition is true. Rows without a match in either table are excluded.

  24. 24

    Which type of join returns all records from the left table and matching records from the right table, with NULLs where there is no match?

    1. A

      CROSS JOIN

    2. B

      RIGHT JOIN

    3. C

      LEFT JOIN

    4. D

      INNER JOIN

    Correct answer
    C

    LEFT JOIN

    Explanation

    A LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table. If there is no match in the right table, NULLs are used for right table columns.

  25. 25

    What is a self join?

    1. A

      Joining two tables that have the same structure

    2. B

      Joining a table with its primary key

    3. C

      Joining a table with a view of itself

    4. D

      Joining a table with itself using different aliases

    Correct answer
    D

    Joining a table with itself using different aliases

    Explanation

    A self join is when a table is joined to itself. This is done by using different aliases for the same table, e.g., to find employee-manager relationships.

  26. 26

    What is a composite primary key?

    1. A

      A primary key that can have duplicate values

    2. B

      A primary key that is automatically generated

    3. C

      A primary key that consists of multiple columns

    4. D

      A primary key that is a foreign key in another table

    Correct answer
    C

    A primary key that consists of multiple columns

    Explanation

    A composite primary key is a primary key made up of two or more columns. For example, in order_items, the combination of order_id and product_id uniquely identifies each row.

  27. 27

    What does the UNION operator do?

    1. A

      It combines rows from two or more queries into a single result set

    2. B

      It joins tables based on a common column

    3. C

      It combines columns from two tables

    4. D

      It returns the intersection of two queries

    Correct answer
    A

    It combines rows from two or more queries into a single result set

    Explanation

    UNION combines the results of multiple SELECT statements into one result set. Each SELECT must have the same number of columns.

  28. 28

    In MySQL Workbench, what does the 'safe update mode' prevent?

    1. A

      Inserting duplicate rows into a table

    2. B

      Executing DDL statements that modify table structure

    3. C

      Updating or deleting multiple rows without a key in the WHERE clause

    4. D

      Running SELECT queries without a WHERE clause

    Correct answer
    C

    Updating or deleting multiple rows without a key in the WHERE clause

    Explanation

    Safe update mode prevents accidental updates or deletes of many rows. It requires a key (e.g., primary key) in the WHERE clause for UPDATE/DELETE on multiple rows.

  29. 29

    How do you insert a new row into a table while letting MySQL auto-generate the primary key value?

    1. A

      Omit the primary key column from the INSERT statement

    2. B

      Use DEFAULT for the primary key column

    3. C

      All of the above

    4. D

      Use NULL for the primary key column

    Correct answer
    C

    All of the above

    Explanation

    You can omit the primary key column (if auto_increment), or explicitly use NULL or DEFAULT. MySQL will generate the next value.

  30. 30

    What function returns the ID generated by an INSERT operation?

    1. A

      GET_LAST_ID()

    2. B

      LAST_INSERT_ID()

    3. C

      CURRENT_INSERT_ID()

    4. D

      IDENTITY()

    Correct answer
    B

    LAST_INSERT_ID()

    Explanation

    LAST_INSERT_ID() is a MySQL function that returns the auto_increment value generated by the most recent INSERT statement.

  31. 31

    Which statement is used to create a new table by copying the result of a query?

    1. A

      INSERT INTO ... SELECT ...

    2. B

      CREATE TABLE ... AS SELECT ...

    3. C

      SELECT ... INTO TABLE ...

    4. D

      CREATE TABLE ... FROM SELECT ...

    Correct answer
    B

    CREATE TABLE ... AS SELECT ...

    Explanation

    In MySQL, 'CREATE TABLE new_table AS SELECT ...' creates a new table and inserts the query results. Note that primary key and auto_increment attributes are not copied.

  32. 32

    What does the UPDATE statement do if no WHERE clause is specified?

    1. A

      It updates only the first row in the table

    2. B

      It updates all rows in the table

    3. C

      It prompts the user to confirm

    4. D

      It does nothing and returns an error

    Correct answer
    B

    It updates all rows in the table

    Explanation

    Without a WHERE clause, the UPDATE statement modifies every row in the table. This is powerful and dangerous, so caution is needed.

  33. 33

    In an UPDATE statement, how can you set a column to its default value?

    1. A

      SET column = DEFAULT

    2. B

      SET column = ''

    3. C

      SET column = 0

    4. D

      SET column = NULL

    Correct answer
    A

    SET column = DEFAULT

    Explanation

    Using the DEFAULT keyword sets the column to its defined default value. For example, if a column has a default of 0, 'SET points = DEFAULT' sets it to 0.

  34. 34

    What is a subquery?

    1. A

      A SELECT statement nested inside another SQL statement

    2. B

      A query that uses the UNION operator

    3. C

      A query that joins more than two tables

    4. D

      A query that returns multiple rows

    Correct answer
    A

    A SELECT statement nested inside another SQL statement

    Explanation

    A subquery is a SELECT statement that is used within another SQL statement (e.g., in WHERE, FROM, or SET clauses). It is enclosed in parentheses.

  35. 35

    When using a subquery in a WHERE clause with an equality operator, what must the subquery return?

    1. A

      A single value

    2. B

      A single row with multiple columns

    3. C

      A list of values

    4. D

      Any number of rows

    Correct answer
    A

    A single value

    Explanation

    If using '=' with a subquery, the subquery must return exactly one value. For multiple values, use IN or other operators.

  36. 36

    Which modifier in MySQL Workbench's 'safe update mode' can be turned off to allow updating multiple rows?

    1. A

      All of the above

    2. B

      Disable 'Safe Updates' in the Connection settings

    3. C

      Uncheck 'Save updates' in SQL Editor preferences

    4. D

      Use the '--safe-updates=0' command

    Correct answer
    C

    Uncheck 'Save updates' in SQL Editor preferences

    Explanation

    In MySQL Workbench, you can disable safe updates by going to Preferences > SQL Editor and unchecking 'Safe Updates' (Save updates).

  37. 37

    How do you delete all rows from a table?

    1. A

      DROP TABLE table_name;

    2. B

      DELETE * FROM table_name;

    3. C

      DELETE FROM table_name;

    4. D

      TRUNCATE table_name;

    Correct answer
    C

    DELETE FROM table_name;

    Explanation

    DELETE FROM table_name without a WHERE clause deletes all rows. TRUNCATE also removes all rows but is faster and cannot be rolled back in some cases.

Question 1 of 37
Question 1 of 37

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent