1. Home
  2. Explore
  3. Computer Science
  4. SQL Fundamentals

Study methods

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

SQL Fundamentals

  • 123Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: SQL Foundations

What is SQL primarily used for?

123 questions

  1. 1

    What is SQL primarily used for?

    1. A

      Designing visual layouts for web applications

    2. B

      Compiling source code into executable programs

    3. C

      Managing network connections between web browsers

    4. D

      Communicating with databases to store and retrieve data

    Correct answer
    D

    Communicating with databases to store and retrieve data

    Explanation

    SQL, or Structured Query Language, is used to communicate with databases and perform operations such as creating, reading, updating, and deleting data.

  2. 2

    Why is SQL useful to developers who primarily use another programming language?

    1. A

      Most web applications use SQL alongside their backend programming language

    2. B

      SQL converts programs written in one language into another language

    3. C

      SQL is required only when developing browser-based user interfaces

    4. D

      SQL automatically replaces the need for all backend programming languages

    Correct answer
    A

    Most web applications use SQL alongside their backend programming language

    Explanation

    Regardless of whether a developer uses JavaScript, Python, Go, or another language, web applications commonly use SQL to interact with databases.

  3. 3

    What does a database primarily provide?

    1. A

      Software for organizing and storing large amounts of data

    2. B

      A compiler that translates SQL into machine instructions

    3. C

      A programming language for building graphical interfaces

    4. D

      A network protocol for transferring files between computers

    Correct answer
    A

    Software for organizing and storing large amounts of data

    Explanation

    A database is software that makes it easier to store and manage large amounts of data in a computer's file system.

  4. 4

    How does using SQL differ from manually using a spreadsheet?

    1. A

      SQL stores data only as images instead of rows and columns

    2. B

      SQL requires every value to be entered by clicking a cell

    3. C

      SQL prevents users from changing stored information

    4. D

      SQL uses code to automate database operations

    Correct answer
    D

    SQL uses code to automate database operations

    Explanation

    Spreadsheets are often manipulated manually, whereas SQL lets developers write code that automates database operations.

  5. 5

    Which set of operations is represented by CRUD?

    1. A

      Copy, replace, undo, and deploy

    2. B

      Compile, run, upload, and download

    3. C

      Create, read, update, and delete

    4. D

      Connect, render, execute, and debug

    Correct answer
    C

    Create, read, update, and delete

    Explanation

    CRUD stands for create, read, update, and delete, the four basic operations performed on stored data.

  6. 6

    Which result does a SQL query normally produce?

    1. A

      Console output containing only one text string

    2. B

      A result set organized into rows and columns

    3. C

      A compiled executable file for the database server

    4. D

      A graphical spreadsheet that cannot be processed by code

    Correct answer
    B

    A result set organized into rows and columns

    Explanation

    SQL queries commonly return a result set formatted as a table containing rows and columns.

  7. 7

    Which statement about SQL keywords is generally correct?

    1. A

      SQL keywords must match the capitalization of table names

    2. B

      SQL keywords must always be written in lowercase

    3. C

      SQL keywords are generally case insensitive

    4. D

      SQL keywords are interpreted as strings unless quoted

    Correct answer
    C

    SQL keywords are generally case insensitive

    Explanation

    SQL is generally case insensitive, although uppercase keywords are commonly used as a readability convention.

  8. 8

    What is a SQL dialect?

    1. A

      A programming language that replaces SQL entirely

    2. B

      A database-specific variation of the common SQL language

    3. C

      A special table containing multiple database schemas

    4. D

      A method for translating SQL queries into spoken language

    Correct answer
    B

    A database-specific variation of the common SQL language

    Explanation

    Different database systems may support slightly different SQL features, data types, or syntax. These variations are called SQL dialects.

  9. 9

    Which statement retrieves every column from the users table?

    1. A

      READ COLUMNS users;

    2. B

      SELECT * FROM users;

    3. C

      SELECT users FROM *;

    4. D

      GET ALL users;

    Correct answer
    B

    SELECT * FROM users;

    Explanation

    The * wildcard represents all columns, so SELECT * FROM users; returns every column from the users table.

  10. 10

    Which query retrieves only the name and balance columns from users?

    1. A

      SELECT name balance AS users;

    2. B

      SELECT name, balance FROM users;

    3. C

      GET name AND balance IN users;

    4. D

      SELECT users FROM name, balance;

    Correct answer
    B

    SELECT name, balance FROM users;

    Explanation

    Multiple columns are listed after SELECT and separated by commas.

  11. 11

    What operation does a SELECT statement represent in CRUD?

    1. A

      A create operation

    2. B

      A delete operation

    3. C

      A read operation

    4. D

      An update operation

    Correct answer
    C

    A read operation

    Explanation

    A SELECT statement reads data from a database, so it corresponds to the read operation in CRUD.

  12. 12

    In SQLite, how are Boolean values represented when returned from a query?

    1. A

      As binary data stored in a blob

    2. B

      As floating-point values between −1-1−1 and 111

    3. C

      As strings such as true and false

    4. D

      As integers such as 000 and 111

    Correct answer
    D

    As integers such as 000 and 111

    Explanation

    SQLite accepts Boolean-like values but represents false and true as the integers 000 and 111 when returning data.

  13. 13

    Which SQL clause filters rows before any grouping or aggregation occurs?

    1. A

      The ORDER BY clause

    2. B

      The LIMIT clause

    3. C

      The HAVING clause

    4. D

      The WHERE clause

    Correct answer
    D

    The WHERE clause

    Explanation

    The WHERE clause filters individual rows before grouping and aggregation take place.

  14. 14

    Which query returns users with administrative privileges?

    1. A

      SELECT is_admin FROM users WHERE users = admin;

    2. B

      GET * FROM users HAVING admin = true;

    3. C

      SELECT users WHERE is_admin IS admin;

    4. D

      SELECT * FROM users WHERE is_admin = true;

    Correct answer
    D

    SELECT * FROM users WHERE is_admin = true;

    Explanation

    The condition is_admin = true filters the users table to rows whose administrative flag is true.

  15. 15

    What does the * wildcard mean in a SELECT list?

    1. A

      Return every table in the database

    2. B

      Return only the primary-key column

    3. C

      Return every column in the selected table

    4. D

      Return only columns containing text

    Correct answer
    C

    Return every column in the selected table

    Explanation

    In a SELECT list, * means all columns from the selected table or tables.

  16. 16

    Which statement correctly describes the IN operator?

    1. A

      It limits a result set to a fixed number of rows

    2. B

      It combines every row from two unrelated tables

    3. C

      It tests whether a value matches one of several listed values

    4. D

      It converts a text value into an integer

    Correct answer
    C

    It tests whether a value matches one of several listed values

    Explanation

    The IN operator is shorthand for comparing a value against multiple possible values, such as country codes.

  17. 17

    Which query selects users from the United States, Canada, or Mexico?

    1. A

      SELECT * FROM users WHERE country_code BETWEEN ('US', 'CA', 'MX');

    2. B

      SELECT * FROM users WHERE country_code CONTAINS ('US', 'CA', 'MX');

    3. C

      SELECT * FROM users WHERE country_code LIKE ('US', 'CA', 'MX');

    4. D

      SELECT * FROM users WHERE country_code IN ('US', 'CA', 'MX');

    Correct answer
    D

    SELECT * FROM users WHERE country_code IN ('US', 'CA', 'MX');

    Explanation

    The IN operator tests whether country_code matches any value in the supplied list.

  18. 18

    How should SQL test whether a value is absent rather than equal to a normal value?

    1. A

      Use EQUALS EMPTY or NOT EMPTY

    2. B

      Use MISSING or PRESENT

    3. C

      Use IS NULL or IS NOT NULL

    4. D

      Use = NULL or != NULL

    Correct answer
    C

    Use IS NULL or IS NOT NULL

    Explanation

    SQL uses the special syntax IS NULL and IS NOT NULL because null represents the absence of a value.

  19. 19

    What does a null value represent in SQL?

    1. A

      The integer zero

    2. B

      A text value with zero characters

    3. C

      A Boolean value of false

    4. D

      The absence of a value

    Correct answer
    D

    The absence of a value

    Explanation

    Null indicates that no value is present. It is different from an empty string, zero, or false.

  20. 20

    What does BETWEEN 13 AND 18 test?

    1. A

      Whether a value is outside the specified range

    2. B

      Whether a value lies within the specified range

    3. C

      Whether a value contains the characters 13 and 18

    4. D

      Whether a value matches either endpoint only

    Correct answer
    B

    Whether a value lies within the specified range

    Explanation

    The BETWEEN operator checks whether a value is within the given lower and upper bounds.

  21. 21

    What is the effect of placing NOT before BETWEEN?

    1. A

      It converts the range into a text pattern

    2. B

      It selects only the two boundary values

    3. C

      It selects values outside the specified range

    4. D

      It removes null values from the result

    Correct answer
    C

    It selects values outside the specified range

    Explanation

    A condition such as NOT BETWEEN 10 AND 20 matches values that are not within that range.

  22. 22

    What does the percent wildcard represent in a LIKE pattern?

    1. A

      Exactly one word

    2. B

      Exactly one character

    3. C

      Zero or more characters

    4. D

      Only numeric characters

    Correct answer
    C

    Zero or more characters

    Explanation

    In a LIKE pattern, % matches zero or more characters.

  23. 23

    Which pattern matches names that start with Al?

    1. A

      'Al%'

    2. B

      '%Al'

    3. C

      'Al_'

    4. D

      '_Al_'

    Correct answer
    A

    'Al%'

    Explanation

    The pattern Al% requires the value to begin with Al and permits any number of characters afterward.

  24. 24

    What does the underscore wildcard represent in a LIKE pattern?

    1. A

      Any number of numeric characters

    2. B

      Exactly one character

    3. C

      One or more words

    4. D

      Zero or more characters

    Correct answer
    B

    Exactly one character

    Explanation

    The underscore wildcard _ matches exactly one character.

  25. 25

    Which pattern matches names that start with Al and contain exactly five characters?

    1. A

      '%Al___'

    2. B

      '_Al__'

    3. C

      'Al%'

    4. D

      'Al___'

    Correct answer
    D

    'Al___'

    Explanation

    The pattern contains Al followed by exactly three underscore wildcards, producing five characters total.

  26. 26

    Which query finds transaction notes containing the word lunch anywhere?

    1. A

      SELECT * FROM transactions WHERE note IN '%lunch%';

    2. B

      SELECT * FROM transactions WHERE note LIKE '%lunch%';

    3. C

      SELECT * FROM transactions WHERE note BETWEEN '%lunch%';

    4. D

      SELECT * FROM transactions WHERE note LIKE 'lunch';

    Correct answer
    B

    SELECT * FROM transactions WHERE note LIKE '%lunch%';

    Explanation

    Percent signs on both sides of lunch allow characters before and after the word.

  27. 27

    What is the purpose of the AND logical operator?

    1. A

      It requires exactly one condition to be true

    2. B

      It combines two columns into one value

    3. C

      It reverses the truth value of a condition

    4. D

      It requires both conditions to be true

    Correct answer
    D

    It requires both conditions to be true

    Explanation

    A condition joined with AND matches only when both conditions evaluate to true.

  28. 28

    What is the purpose of the OR logical operator?

    1. A

      It requires at least one condition to be true

    2. B

      It requires exactly one condition to be true

    3. C

      It requires both conditions to be false

    4. D

      It removes conditions from the query

    Correct answer
    A

    It requires at least one condition to be true

    Explanation

    OR matches when at least one of its conditions is true; both conditions may also be true.

  29. 29

    Why are parentheses useful in SQL conditions involving AND and OR?

    1. A

      They automatically create a new database table

    2. B

      They convert all conditions into text comparisons

    3. C

      They control the order in which conditions are evaluated

    4. D

      They prevent the query from returning null values

    Correct answer
    C

    They control the order in which conditions are evaluated

    Explanation

    Parentheses group conditions and determine which logical expressions are evaluated together first.

  30. 30

    Which operator tests equality in a SQL condition?

    1. A

      A single equals sign, =

    2. B

      A double equals sign, ==

    3. C

      The keyword EQUALS

    4. D

      A triple equals sign, ===

    Correct answer
    A

    A single equals sign, =

    Explanation

    SQL uses a single equals sign for equality comparisons in conditions.

  31. 31

    What does the LIMIT clause do?

    1. A

      It limits a comparison to numeric values

    2. B

      It prevents all future inserts into a table

    3. C

      It caps the number of rows returned

    4. D

      It restricts the number of columns in a table permanently

    Correct answer
    C

    It caps the number of rows returned

    Explanation

    LIMIT returns no more than the specified number of rows.

  32. 32

    Why might a developer use LIMIT when querying a production database?

    1. A

      To guarantee that exactly that many rows exist

    2. B

      To avoid retrieving an excessively large result set

    3. C

      To force the database to delete extra rows

    4. D

      To make every query return at least that many rows

    Correct answer
    B

    To avoid retrieving an excessively large result set

    Explanation

    Limiting results reduces the amount of data transferred and helps avoid unnecessary strain on the database and application.

  33. 33

    What happens if a query with LIMIT 5 naturally matches only two rows?

    1. A

      It returns two rows

    2. B

      It creates three additional empty rows

    3. C

      It produces an error because five rows are unavailable

    4. D

      It returns exactly five rows with duplicates

    Correct answer
    A

    It returns two rows

    Explanation

    LIMIT 5 means no more than five rows, not exactly five rows.

  34. 34

    What is the default sort direction for ORDER BY?

    1. A

      Insertion order only

    2. B

      Ascending order

    3. C

      Descending order

    4. D

      Random order

    Correct answer
    B

    Ascending order

    Explanation

    Unless DESC is specified, ORDER BY sorts values in ascending order.

  35. 35

    Which query returns the largest transaction amounts first and only returns four rows?

    1. A

      SELECT * FROM transactions ORDER BY amount DESC LIMIT 4;

    2. B

      SELECT * FROM transactions SORT amount DESC TAKE 4;

    3. C

      SELECT * FROM transactions ORDER BY amount ASC LIMIT 4;

    4. D

      SELECT * FROM transactions LIMIT 4 ORDER BY amount DESC;

    Correct answer
    A

    SELECT * FROM transactions ORDER BY amount DESC LIMIT 4;

    Explanation

    The rows must be sorted with ORDER BY amount DESC before the result is limited to four rows.

  36. 36

    What does DISTINCT do in a query?

    1. A

      It removes duplicate values from the selected result

    2. B

      It selects only rows containing null values

    3. C

      It permanently removes duplicate rows from the table

    4. D

      It sorts values from smallest to largest

    Correct answer
    A

    It removes duplicate values from the selected result

    Explanation

    DISTINCT removes repeated values from the query result, but it does not delete data from the underlying table.

  37. 37

    Which query returns each country code only once?

    1. A

      SELECT DISTINCT country_code FROM users;

    2. B

      SELECT UNIQUE ROW country_code FROM users;

    3. C

      SELECT country_code WITHOUT DUPLICATES users;

    4. D

      SELECT country_code GROUP users;

    Correct answer
    A

    SELECT DISTINCT country_code FROM users;

    Explanation

    SELECT DISTINCT country_code FROM users; returns one result for each unique country code.

  38. 38

    Which SQL statement inserts new rows into a table?

    1. A

      The INSERT INTO statement

    2. B

      The CREATE RECORD statement

    3. C

      The ADD ROW statement

    4. D

      The APPEND TABLE statement

    Correct answer
    A

    The INSERT INTO statement

    Explanation

    INSERT INTO adds new records to an existing table.

  39. 39

    Why must the order of values in an INSERT statement match the listed columns?

    1. A

      SQL accepts values only when columns are alphabetized

    2. B

      Values are assigned randomly unless the columns are ordered

    3. C

      The database ignores column names during insertion

    4. D

      Each value is assigned to the column in the corresponding position

    Correct answer
    D

    Each value is assigned to the column in the corresponding position

    Explanation

    When columns and values are listed positionally, the first value goes to the first column, the second to the second, and so on.

  40. 40

    What does an auto-incrementing ID provide when inserting a new row?

    1. A

      The database automatically encrypts every inserted value

    2. B

      The database automatically creates a unique username

    3. C

      The database automatically deletes the previous row

    4. D

      The database automatically generates the next identifier

    Correct answer
    D

    The database automatically generates the next identifier

    Explanation

    Auto-incrementing IDs allow the database to assign the next available sequential identifier without requiring the application to calculate it first.

  41. 41

    What is a UUID commonly used for?

    1. A

      A randomly generated identifier for a record

    2. B

      A query that returns multiple rows

    3. C

      A password hashing algorithm

    4. D

      A Boolean value stored in a database

    Correct answer
    A

    A randomly generated identifier for a record

    Explanation

    A UUID is a very large randomly generated identifier. Its many possible combinations make collisions extremely unlikely.

  42. 42

    Which SQL statement changes existing rows?

    1. A

      The MODIFY TABLE statement

    2. B

      The CHANGE RECORD statement

    3. C

      The ALTER VALUE statement

    4. D

      The UPDATE statement

    Correct answer
    D

    The UPDATE statement

    Explanation

    The UPDATE statement changes values in existing rows, usually with a SET clause and a filtering WHERE clause.

  43. 43

    Why should an UPDATE statement usually include a specific WHERE clause?

    1. A

      Without it, the query cannot identify the table

    2. B

      Without it, SQL automatically converts values to null

    3. C

      Without it, unintended rows may be updated

    4. D

      Without it, only the primary key can be changed

    Correct answer
    C

    Without it, unintended rows may be updated

    Explanation

    A missing or overly broad WHERE clause can cause the update to affect many more rows than intended.

  44. 44

    What does DELETE FROM users; do when no WHERE clause is included?

    1. A

      It deletes only the first row in the users table

    2. B

      It deletes the users table structure but keeps its rows

    3. C

      It produces an error because deletion requires an ID

    4. D

      It deletes every row in the users table

    Correct answer
    D

    It deletes every row in the users table

    Explanation

    Without a WHERE clause, DELETE FROM users; targets every row in the table.

  45. 45

    Why is deleting by a primary key safer than deleting by a common name?

    1. A

      Names are always stored as null values

    2. B

      A primary key identifies one specific row

    3. C

      Names cannot be used in SQL conditions

    4. D

      Primary keys automatically create backups

    Correct answer
    B

    A primary key identifies one specific row

    Explanation

    A primary key is unique, whereas multiple records may share the same name.

  46. 46

    What is the purpose of CREATE TABLE?

    1. A

      To retrieve rows from an existing table

    2. B

      To rename a database server

    3. C

      To create an index on an existing column

    4. D

      To define a new table and its columns

    Correct answer
    D

    To define a new table and its columns

    Explanation

    CREATE TABLE defines a table name and the columns, data types, and constraints it contains.

  47. 47

    What is a database schema?

    1. A

      The structure describing how data is organized

    2. B

      A backup copy of every row in a database

    3. C

      A query result containing only primary keys

    4. D

      A programming language used to access databases

    Correct answer
    A

    The structure describing how data is organized

    Explanation

    A schema includes the tables, column names, data types, relationships, and constraints used to organize data.

  48. 48

    What is the difference between a row and a column in a table?

    1. A

      A row represents a data type, while a column represents a database

    2. B

      A row represents a constraint, while a column represents a backup

    3. C

      A row represents a table, while a column represents a query

    4. D

      A row represents a record, while a column represents an attribute

    Correct answer
    D

    A row represents a record, while a column represents an attribute

    Explanation

    Each row is an individual record, and each column stores a particular attribute of those records.

  49. 49

    Which SQLite data type is used for whole numbers that may be negative?

    1. A

      Blob

    2. B

      Integer

    3. C

      Text

    4. D

      Real

    Correct answer
    B

    Integer

    Explanation

    SQLite integers represent whole numbers, including negative values.

  50. 50

    Which SQLite data type is intended for numbers with fractional parts?

    1. A

      Real

    2. B

      Null

    3. C

      Text

    4. D

      Integer

    Correct answer
    A

    Real

    Explanation

    SQLite uses the real type for floating-point values or numbers with fractional parts.

  51. 51

    What is a blob typically used to store?

    1. A

      A Boolean condition

    2. B

      A database table name

    3. C

      Large binary data

    4. D

      A sequence of whole numbers only

    Correct answer
    C

    Large binary data

    Explanation

    A blob stores binary data, such as raw file contents or other non-text data.

  52. 52

    Why might a database use VARCHAR instead of a general text type?

    1. A

      The maximum length of the text is known

    2. B

      The value must always be numeric

    3. C

      The value must be stored as binary data

    4. D

      The column is required to contain a primary key

    Correct answer
    A

    The maximum length of the text is known

    Explanation

    A VARCHAR can specify a maximum character length, allowing some database systems to make storage or performance optimizations.

  53. 53

    What does a NOT NULL constraint prevent?

    1. A

      It prevents a query from returning text values

    2. B

      It prevents a column from receiving duplicate values

    3. C

      It prevents a table from having more than one row

    4. D

      It prevents a column from receiving null values

    Correct answer
    D

    It prevents a column from receiving null values

    Explanation

    A NOT NULL constraint requires a value to be present in the column for each inserted or updated row.

  54. 54

    Which property does a primary key provide?

    1. A

      Permission to store multiple identical rows

    2. B

      Uniqueness and non-null identification of each row

    3. C

      Automatic encryption of every column

    4. D

      Automatic conversion of text into integers

    Correct answer
    B

    Uniqueness and non-null identification of each row

    Explanation

    A primary key uniquely identifies each row and also cannot be null.

  55. 55

    How many primary keys can a table have?

    1. A

      One primary key for every column

    2. B

      Exactly two primary keys

    3. C

      One primary key constraint

    4. D

      An unlimited number of primary keys

    Correct answer
    C

    One primary key constraint

    Explanation

    A table can have only one primary key constraint, although that key may consist of multiple columns in some database systems.

  56. 56

    What does a UNIQUE constraint enforce?

    1. A

      Every row must contain a foreign key

    2. B

      Every value must be a positive integer

    3. C

      The column must also be the primary key

    4. D

      No two non-null values in the constrained column may be identical

    Correct answer
    D

    No two non-null values in the constrained column may be identical

    Explanation

    A unique constraint prevents duplicate values, although its null behavior can differ from that of a primary key.

  57. 57

    What is a foreign key?

    1. A

      A query that joins unrelated databases

    2. B

      A table that contains no primary key

    3. C

      A column that stores encrypted passwords

    4. D

      A column that references a key in another table

    Correct answer
    D

    A column that references a key in another table

    Explanation

    A foreign key establishes a relationship by referencing a key, usually the primary key, in another table.

  58. 58

    What does a foreign key constraint help guarantee?

    1. A

      The referenced record exists in the related table

    2. B

      Every record in the table has the same name

    3. C

      Every query using the table runs in constant time

    4. D

      The related table contains no duplicate columns

    Correct answer
    A

    The referenced record exists in the related table

    Explanation

    A foreign key constraint prevents references to nonexistent records in the related table.

  59. 59

    Which example represents a one-to-many relationship?

    1. A

      One transaction can have exactly one database

    2. B

      One column can have only one data type

    3. C

      One country code can contain many characters

    4. D

      One user can have many transactions

    Correct answer
    D

    One user can have many transactions

    Explanation

    A user may be associated with zero or many transactions, which is a one-to-many relationship.

  60. 60

    Where is a foreign key usually placed in a one-to-many relationship?

    1. A

      In a third table with no identifiers

    2. B

      On the table representing the one side only

    3. C

      In the database server configuration

    4. D

      On the table representing the many side

    Correct answer
    D

    On the table representing the many side

    Explanation

    The table on the many side stores a foreign key pointing to the table on the one side.

  61. 61

    How is a many-to-many relationship usually modeled?

    1. A

      With a joining table containing identifiers from both entities

    2. B

      With one text column containing all related records

    3. C

      By duplicating the entire database for each relationship

    4. D

      By placing every related record in the primary key

    Correct answer
    A

    With a joining table containing identifiers from both entities

    Explanation

    A joining table stores pairs of foreign keys, allowing many records on either side to be related.

  62. 62

    What is the primary purpose of a joining table?

    1. A

      To store all metadata for one entity

    2. B

      To model relationships between two entity tables

    3. C

      To cache the result of every SQL query

    4. D

      To replace every primary key in the database

    Correct answer
    B

    To model relationships between two entity tables

    Explanation

    A joining table usually contains identifiers from two tables and represents the relationships between them.

  63. 63

    Why might a unique constraint cover two columns in a joining table?

    1. A

      To make both columns independent primary keys

    2. B

      To require both columns to contain text

    3. C

      To ensure every entity has exactly two relationships

    4. D

      To prevent the same relationship from being recorded twice

    Correct answer
    D

    To prevent the same relationship from being recorded twice

    Explanation

    A composite uniqueness constraint prevents duplicate pairs such as the same user ID and group ID appearing twice.

  64. 64

    What is an inner join's defining behavior?

    1. A

      It returns every row from both tables regardless of matches

    2. B

      It returns only unmatched rows from the second table

    3. C

      It returns rows with matching records in both tables

    4. D

      It returns every row from the first table regardless of matches

    Correct answer
    C

    It returns rows with matching records in both tables

    Explanation

    An inner join returns only records that have matching values according to the join condition in both tables.

  65. 65

    What does a left join preserve?

    1. A

      Every row from the left table

    2. B

      Only rows that have no matching record

    3. C

      Only rows present in both tables

    4. D

      Every row from the right table

    Correct answer
    A

    Every row from the left table

    Explanation

    A left join returns every row from the left table and matching rows from the right table when they exist.

  66. 66

    What happens to right-table columns when a left join has no match?

    1. A

      They contain null values

    2. B

      They cause the entire query to fail

    3. C

      They are filled with zeros

    4. D

      They are copied from the left table

    Correct answer
    A

    They contain null values

    Explanation

    When a left-table row has no matching right-table row, the right-table columns are returned as null.

  67. 67

    Why can a right join usually be replaced by a left join?

    1. A

      Left joins automatically return every table

    2. B

      The table order can be reversed

    3. C

      Right joins never use matching conditions

    4. D

      Right joins are identical to cross joins

    Correct answer
    B

    The table order can be reversed

    Explanation

    Swapping the order of the tables and using a left join produces the equivalent result.

  68. 68

    What does a full join return?

    1. A

      Only rows with a match in both tables

    2. B

      Only rows that are missing from both tables

    3. C

      All rows from both tables, matched when possible

    4. D

      Every row from the left table only

    Correct answer
    C

    All rows from both tables, matched when possible

    Explanation

    A full join preserves every row from both tables and fills unmatched columns with null values.

  69. 69

    What is the purpose of the ON clause in a join?

    1. A

      It determines how many rows the query returns

    2. B

      It defines the data type of every joined column

    3. C

      It specifies how rows from the tables are related

    4. D

      It sorts the joined result alphabetically

    Correct answer
    C

    It specifies how rows from the tables are related

    Explanation

    The ON clause provides the matching condition, such as one table's foreign key equaling another table's primary key.

  70. 70

    Why are table-qualified names such as users.id useful?

    1. A

      They identify which table a column comes from

    2. B

      They automatically create a table alias

    3. C

      They prevent all null values in the result

    4. D

      They convert a column into a primary key

    Correct answer
    A

    They identify which table a column comes from

    Explanation

    Table-qualified names resolve ambiguity when multiple joined tables contain columns with the same name.

  71. 71

    What is a database migration?

    1. A

      A method for changing a programming language

    2. B

      A backup stored only in application memory

    3. C

      An incremental change to a database schema

    4. D

      A query that reads every row in a table

    Correct answer
    C

    An incremental change to a database schema

    Explanation

    A migration changes the database structure, such as adding a table or column, in a controlled and incremental way.

  72. 72

    Why is adding a new table or column generally safer than removing one?

    1. A

      Existing application code usually does not depend on the new resource

    2. B

      New tables cannot contain constraints

    3. C

      Removing data never affects application behavior

    4. D

      New columns automatically repair all existing data

    Correct answer
    A

    Existing application code usually does not depend on the new resource

    Explanation

    Existing code generally does not query a resource that did not previously exist, whereas removing a resource may break code that still uses it.

  73. 73

    What should generally happen first when removing a database column used by an application?

    1. A

      Update the application code to stop using the column

    2. B

      Add more queries that depend on the column

    3. C

      Delete the production database immediately

    4. D

      Create a second primary key for the column

    Correct answer
    A

    Update the application code to stop using the column

    Explanation

    The application should stop querying the resource before the database column is removed.

  74. 74

    Why are renaming migrations particularly difficult?

    1. A

      SQL databases cannot store renamed tables

    2. B

      Old and new application versions may expect different names

    3. C

      Renaming always changes every stored value

    4. D

      Renaming prevents all future inserts

    Correct answer
    B

    Old and new application versions may expect different names

    Explanation

    During a rename, old code may reference the old name while new code references the new name, creating a deployment coordination problem.

  75. 75

    What is an up migration?

    1. A

      A migration that reverses the previous migration

    2. B

      A migration that copies data into memory

    3. C

      A migration that restores deleted user records

    4. D

      A migration that moves the schema forward

    Correct answer
    D

    A migration that moves the schema forward

    Explanation

    Up migrations apply new schema changes and move the database toward a newer state.

  76. 76

    What is a down migration used for?

    1. A

      Sorting rows in descending order

    2. B

      Adding a foreign key automatically

    3. C

      Creating a new production snapshot

    4. D

      Rolling back a related schema change

    Correct answer
    D

    Rolling back a related schema change

    Explanation

    A down migration reverses an earlier up migration, usually to recover from a problem.

  77. 77

    Which strategy is generally the safest for renaming a table when supported?

    1. A

      Rename the table without changing any application code

    2. B

      Delete the table and recreate it without copying data

    3. C

      Alias the table so old and new code can reference it

    4. D

      Run old and new code against unrelated tables permanently

    Correct answer
    C

    Alias the table so old and new code can reference it

    Explanation

    Aliasing allows both the old and new names to work during deployment, after which the old name can be removed.

  78. 78

    What is a database backup snapshot?

    1. A

      A stored copy of the database at a particular time

    2. B

      A temporary alias for a table name

    3. C

      A live query that continuously changes the database

    4. D

      A constraint that prevents data deletion

    Correct answer
    A

    A stored copy of the database at a particular time

    Explanation

    A snapshot captures the database state at a specific time so it can later be restored.

  79. 79

    What is the main limitation of taking only daily database snapshots?

    1. A

      Snapshots prevent all future database writes

    2. B

      Snapshots automatically duplicate every table forever

    3. C

      Snapshots cannot be stored in cloud storage

    4. D

      Data added after the latest snapshot may be lost

    Correct answer
    D

    Data added after the latest snapshot may be lost

    Explanation

    If a failure occurs between snapshots, restoring the previous snapshot loses changes made since that snapshot.

  80. 80

    How can more frequent snapshots reduce potential data loss?

    1. A

      They eliminate the need for any database schema

    2. B

      They shorten the interval of changes missing from the latest backup

    3. C

      They prevent developers from deleting rows

    4. D

      They guarantee that no backup will ever fail

    Correct answer
    B

    They shorten the interval of changes missing from the latest backup

    Explanation

    Hourly snapshots, for example, reduce the maximum period of lost changes compared with daily snapshots.

  81. 81

    What is an append-only log used for in a robust backup strategy?

    1. A

      Replacing the production database during normal operation

    2. B

      Deleting old records before each snapshot

    3. C

      Recording database changes so they can be replayed

    4. D

      Sorting all rows by their primary keys

    Correct answer
    C

    Recording database changes so they can be replayed

    Explanation

    An append-only log records events such as inserts and deletes, allowing changes to be replayed to reconstruct a later state.

  82. 82

    What is a soft delete?

    1. A

      Deleting a row from a backup but not production

    2. B

      Marking a row as deleted without physically removing it

    3. C

      Removing a table name while preserving all queries

    4. D

      Deleting a row only after asking for confirmation

    Correct answer
    B

    Marking a row as deleted without physically removing it

    Explanation

    A soft delete usually records a deletion marker, such as a deleted_at timestamp, and filters marked rows from normal queries.

  83. 83

    What is a disadvantage of soft deletes?

    1. A

      They guarantee that large tables become faster

    2. B

      They add application complexity and may create privacy concerns

    3. C

      They remove the need for filtering in queries

    4. D

      They make it impossible to recover deleted records

    Correct answer
    B

    They add application complexity and may create privacy concerns

    Explanation

    Applications must consistently exclude soft-deleted rows, and retaining deleted personal data may conflict with privacy requirements.

  84. 84

    What does the SUM aggregation return?

    1. A

      The total of numeric values in a column

    2. B

      The average of all text values

    3. C

      The largest numeric value in a column

    4. D

      The number of rows in a table

    Correct answer
    A

    The total of numeric values in a column

    Explanation

    SUM adds numeric values, such as transaction amounts.

  85. 85

    What does the COUNT aggregation return?

    1. A

      The alphabetically first text value

    2. B

      The number of tables in a database server

    3. C

      The total monetary value of a column

    4. D

      The number of rows or values being counted

    Correct answer
    D

    The number of rows or values being counted

    Explanation

    COUNT aggregates multiple rows into a count, such as the number of users or transactions.

  86. 86

    What does the MAX aggregation return?

    1. A

      The middle value in a sorted set

    2. B

      The largest value in a set

    3. C

      The number of values in a set

    4. D

      The smallest value in a set

    Correct answer
    B

    The largest value in a set

    Explanation

    MAX returns the greatest value among the values being aggregated.

  87. 87

    What does the MIN aggregation return?

    1. A

      The number of distinct tables in a set

    2. B

      The largest value in a set

    3. C

      The smallest value in a set

    4. D

      The total of all values in a set

    Correct answer
    C

    The smallest value in a set

    Explanation

    MIN returns the lowest value among the values being aggregated.

  88. 88

    What does the AVG aggregation do with null values?

    1. A

      It treats every null as the largest value

    2. B

      It ignores null values when calculating the average

    3. C

      It treats every null as the number zero

    4. D

      It causes the entire query to return null

    Correct answer
    B

    It ignores null values when calculating the average

    Explanation

    The average is calculated from values that exist; null values are excluded.

  89. 89

    What is the purpose of GROUP BY?

    1. A

      To divide rows into groups for separate aggregation

    2. B

      To remove all duplicate rows permanently

    3. C

      To sort every row alphabetically

    4. D

      To combine unrelated tables without a join

    Correct answer
    A

    To divide rows into groups for separate aggregation

    Explanation

    GROUP BY creates groups, allowing an aggregate such as SUM or COUNT to be calculated separately for each group.

  90. 90

    What is the difference between WHERE and HAVING?

    1. A

      WHERE creates tables, while HAVING deletes tables

    2. B

      WHERE filters rows before grouping, while HAVING filters groups after aggregation

    3. C

      WHERE filters groups after aggregation, while HAVING filters columns before grouping

    4. D

      WHERE sorts rows, while HAVING limits the number of rows

    Correct answer
    B

    WHERE filters rows before grouping, while HAVING filters groups after aggregation

    Explanation

    WHERE applies before grouping and aggregation. HAVING applies to the grouped results.

  91. 91

    Which clause should filter groups whose transaction total exceeds $20?

    1. A

      The WHERE clause

    2. B

      The LIMIT clause

    3. C

      The ORDER BY clause

    4. D

      The HAVING clause

    Correct answer
    D

    The HAVING clause

    Explanation

    A transaction total is an aggregate result, so filtering it requires HAVING after grouping.

  92. 92

    Why is money often stored as an integer number of smaller units?

    1. A

      Integer columns can store unlimited text values

    2. B

      Integers automatically encrypt financial transactions

    3. C

      Integer arithmetic avoids floating-point rounding problems

    4. D

      Integers automatically calculate exchange rates

    Correct answer
    C

    Integer arithmetic avoids floating-point rounding problems

    Explanation

    Financial systems often store cents or pennies as integers because floating-point calculations can introduce rounding errors.

  93. 93

    What is an ORM?

    1. A

      A network protocol used by web browsers

    2. B

      A database backup format for cloud storage

    3. C

      A SQL command that removes duplicate rows

    4. D

      A library that maps application objects to database records

    Correct answer
    D

    A library that maps application objects to database records

    Explanation

    Object-relational mapping libraries connect in-memory objects or structs with relational database tables and rows.

  94. 94

    What is a typical advantage of using an ORM?

    1. A

      It eliminates the need to understand database schemas

    2. B

      It gives more low-level control than raw SQL

    3. C

      It makes common database operations less verbose

    4. D

      It guarantees every query is faster

    Correct answer
    C

    It makes common database operations less verbose

    Explanation

    An ORM can generate common SQL operations through methods and functions, reducing the amount of code developers write.

  95. 95

    What trade-off does an ORM commonly make?

    1. A

      It trades SQL compatibility for manual typing

    2. B

      It trades some control for simplicity

    3. C

      It trades data integrity for encryption

    4. D

      It trades database storage for network bandwidth

    Correct answer
    B

    It trades some control for simplicity

    Explanation

    ORMs simplify common operations but can obscure or limit direct control over the SQL being executed.

  96. 96

    How does a typical frontend communicate with a cloud-hosted database?

    1. A

      The frontend sends HTTP requests to a backend, which uses SQL

    2. B

      The frontend writes directly to database files in the cloud

    3. C

      The database sends SQL directly to the user's browser

    4. D

      The frontend replaces HTTP requests with spreadsheet commands

    Correct answer
    A

    The frontend sends HTTP requests to a backend, which uses SQL

    Explanation

    In a common web architecture, the frontend communicates with the backend over HTTP, and the backend communicates with the database using SQL.

  97. 97

    Which HTTP method commonly corresponds to a SQL read operation?

    1. A

      POST

    2. B

      PUT

    3. C

      DELETE

    4. D

      GET

    Correct answer
    D

    GET

    Explanation

    An HTTP GET request commonly asks the backend to retrieve data, corresponding to a SQL read.

  98. 98

    Which HTTP method commonly corresponds to creating a new database record?

    1. A

      GET

    2. B

      POST

    3. C

      DELETE

    4. D

      PUT

    Correct answer
    B

    POST

    Explanation

    An HTTP POST request commonly creates a new resource, corresponding to an SQL insert.

  99. 99

    What is SQL injection?

    1. A

      A method for automatically indexing every database column

    2. B

      A backup technique that stores queries in a log

    3. C

      An attack that manipulates a query through unsafely inserted user input

    4. D

      A process for converting SQL into a programming language

    Correct answer
    C

    An attack that manipulates a query through unsafely inserted user input

    Explanation

    SQL injection occurs when untrusted input changes the structure or meaning of a SQL query.

  100. 100

    How should applications protect dynamic SQL values from SQL injection?

    1. A

      Store every input as a table name

    2. B

      Use parameterized queries or safe database-library interpolation

    3. C

      Remove all WHERE clauses from generated queries

    4. D

      Concatenate all user input directly into SQL strings

    Correct answer
    B

    Use parameterized queries or safe database-library interpolation

    Explanation

    Parameterized queries and safe database-library APIs separate user data from SQL syntax and protect against injection.

  101. 101

    Why is ordinary string concatenation dangerous when constructing SQL?

    1. A

      String concatenation changes every integer into a Boolean

    2. B

      User input may be interpreted as executable SQL syntax

    3. C

      String concatenation automatically deletes null values

    4. D

      String concatenation prevents all database reads

    Correct answer
    B

    User input may be interpreted as executable SQL syntax

    Explanation

    If untrusted input is concatenated directly into a query, it may add commands or alter the intended SQL operation.

  102. 102

    What is the primary goal of database normalization?

    1. A

      Reduce data redundancy and improve data integrity

    2. B

      Guarantee that every query runs instantly

    3. C

      Make every query use more duplicate data

    4. D

      Replace all relational tables with JSON blobs

    Correct answer
    A

    Reduce data redundancy and improve data integrity

    Explanation

    Normalization organizes data to reduce duplication and make stored information more consistent and reliable.

  103. 103

    What is the main rule of first normal form?

    1. A

      Every table must contain exactly two columns

    2. B

      Every relationship must be many-to-many

    3. C

      Rows must be uniquely identifiable and tables must not be nested

    4. D

      Every column must contain only integers

    Correct answer
    C

    Rows must be uniquely identifiable and tables must not be nested

    Explanation

    First normal form requires unique rows, typically through a primary key, and prohibits nested tables.

  104. 104

    What additional dependency rule defines second normal form?

    1. A

      Non-key columns must depend on the entire primary key

    2. B

      Every table must have at least two primary keys

    3. C

      All columns must contain unique values

    4. D

      Every row must reference a different table

    Correct answer
    A

    Non-key columns must depend on the entire primary key

    Explanation

    Second normal form requires that non-key columns depend on the complete primary key rather than only part of a composite key.

  105. 105

    What rule is associated with third normal form?

    1. A

      Non-key columns should depend only on the primary key

    2. B

      Every table must avoid using integer values

    3. C

      Every column must store a foreign key

    4. D

      Every table must contain a composite primary key

    Correct answer
    A

    Non-key columns should depend only on the primary key

    Explanation

    Third normal form removes dependencies in which a non-key column depends on another non-key column rather than directly on the primary key.

  106. 106

    What additional issue does Boyce-Codd normal form address?

    1. A

      A primary-key column depending on a non-key column

    2. B

      A database containing more than one table

    3. C

      A table containing no text columns

    4. D

      A query returning too few rows

    Correct answer
    A

    A primary-key column depending on a non-key column

    Explanation

    Boyce-Codd normal form addresses cases involving multiple candidate keys where a key attribute depends on a non-key attribute.

  107. 107

    Which normal form represents the most normalized level among those discussed?

    1. A

      First normal form

    2. B

      Boyce-Codd normal form

    3. C

      Second normal form

    4. D

      Third normal form

    Correct answer
    B

    Boyce-Codd normal form

    Explanation

    Boyce-Codd normal form builds on the rules of first, second, and third normal form and adds an additional constraint.

  108. 108

    Why is storing a user's birthday generally better than storing only their age?

    1. A

      A birthday automatically functions as a primary key

    2. B

      Age cannot be calculated from a birthday

    3. C

      Age becomes outdated over time, while the birthday remains stable

    4. D

      Birthdays require less storage than every possible integer

    Correct answer
    C

    Age becomes outdated over time, while the birthday remains stable

    Explanation

    A stored age becomes inaccurate as time passes, while an application can calculate the current age from a stable birthday.

  109. 109

    What is data redundancy?

    1. A

      A table containing a single primary key

    2. B

      Unnecessary duplication of the same information

    3. C

      A query that returns a calculated value

    4. D

      A column containing a null value

    Correct answer
    B

    Unnecessary duplication of the same information

    Explanation

    Data redundancy occurs when the same information is stored in multiple places without a necessary reason.

  110. 110

    Why can duplicate data reduce data integrity?

    1. A

      Duplicate data automatically converts values to null

    2. B

      Duplicate data prevents all queries from running

    3. C

      Duplicate data guarantees that every record is unique

    4. D

      One copy may be updated while another remains outdated

    Correct answer
    D

    One copy may be updated while another remains outdated

    Explanation

    Multiple copies of a value can become inconsistent when an update is applied to only some copies.

  111. 111

    When might denormalization be justified?

    1. A

      Before the schema and relationships are understood

    2. B

      Whenever developers want less accurate data

    3. C

      When duplicate or precomputed data is needed to improve performance

    4. D

      Whenever a database contains more than one table

    Correct answer
    C

    When duplicate or precomputed data is needed to improve performance

    Explanation

    Denormalization can reduce expensive joins or aggregations, but it introduces redundancy and should generally be used only when performance requires it.

  112. 112

    What is the recommended starting point for database design regarding normalization?

    1. A

      Start normalized and denormalize only when necessary

    2. B

      Avoid primary keys until performance becomes a problem

    3. C

      Start fully denormalized and normalize after production failures

    4. D

      Duplicate every frequently accessed value immediately

    Correct answer
    A

    Start normalized and denormalize only when necessary

    Explanation

    A normalized design generally improves correctness and maintainability; denormalization can be added later for demonstrated performance needs.

  113. 113

    What is a database index?

    1. A

      An auxiliary structure that makes lookups faster

    2. B

      A complete backup of every database table

    3. C

      A list of every SQL keyword supported by a database

    4. D

      A constraint that prevents all inserts

    Correct answer
    A

    An auxiliary structure that makes lookups faster

    Explanation

    An index is an additional database structure, often based on a tree, that helps locate rows efficiently.

  114. 114

    What data structure commonly supports SQL index lookups?

    1. A

      A plain text file without ordering

    2. B

      A stack of unsorted values

    3. C

      A circular queue

    4. D

      A binary tree

    Correct answer
    D

    A binary tree

    Explanation

    SQL databases commonly use tree structures, such as binary-tree variants, to locate sorted values efficiently.

  115. 115

    What is the approximate lookup complexity of a balanced tree index?

    1. A

      O(n2)O(n^2)O(n2)

    2. B

      O(1)O(1)O(1)

    3. C

      O(n)O(n)O(n)

    4. D

      O(log⁡n)O(\log n)O(logn)

    Correct answer
    D

    O(log⁡n)O(\log n)O(logn)

    Explanation

    A balanced tree can locate a value in approximately logarithmic time, O(log⁡n)O(\log n)O(logn), rather than scanning all nnn rows.

  116. 116

    Why should developers avoid indexing every column automatically?

    1. A

      Indexes prevent the column from being queried

    2. B

      Indexes store data only in temporary memory

    3. C

      Indexes make primary keys non-unique

    4. D

      Indexes consume memory and can slow inserts and updates

    Correct answer
    D

    Indexes consume memory and can slow inserts and updates

    Explanation

    Indexes improve reads but consume resources and must be updated when rows are inserted or changed.

  117. 117

    When is a single-column index especially useful?

    1. A

      When a table contains no primary key

    2. B

      When every row must contain a different table

    3. C

      When a column is never referenced in queries

    4. D

      When a column is frequently used for lookups

    Correct answer
    D

    When a column is frequently used for lookups

    Explanation

    A frequently queried column, such as an email used for login, may benefit from an index.

  118. 118

    How do indexes affect writes?

    1. A

      They make every insert instantaneous

    2. B

      They can slow writes because index structures must be updated

    3. C

      They remove the need to store the inserted row

    4. D

      They prevent updates to indexed columns

    Correct answer
    B

    They can slow writes because index structures must be updated

    Explanation

    When data changes, associated index structures must also be updated, adding write overhead.

  119. 119

    What is a multi-column index designed to support?

    1. A

      Storage of multiple unrelated tables in one column

    2. B

      Lookups involving a specific combination of columns

    3. C

      Queries that never use a WHERE clause

    4. D

      Automatic conversion of all columns to text

    Correct answer
    B

    Lookups involving a specific combination of columns

    Explanation

    A multi-column index is useful when queries commonly filter using a particular combination of fields.

  120. 120

    Why does the order of columns matter in a multi-column index?

    1. A

      Column order determines whether values are nullable

    2. B

      The database ignores all columns after the first

    3. C

      Only the last column can be used in a lookup

    4. D

      The index is ordered first by its leading column

    Correct answer
    D

    The index is ordered first by its leading column

    Explanation

    A lookup using the first column of a multi-column index can benefit substantially, while a lookup using only later columns may not.

  121. 121

    Which query operation typically benefits from an index?

    1. A

      Writing comments in application source code

    2. B

      Filtering rows with a WHERE condition

    3. C

      Changing the database server's hostname

    4. D

      Deleting an unused SQL keyword

    Correct answer
    B

    Filtering rows with a WHERE condition

    Explanation

    Indexes are primarily used to speed up lookups, especially conditions such as WHERE email = ....

  122. 122

    Which statement about raw data and aggregations is generally recommended?

    1. A

      Store every possible aggregate in a separate table

    2. B

      Avoid storing data that may later be aggregated

    3. C

      Store only aggregate results and discard the raw data

    4. D

      Store raw data and calculate aggregates when needed

    Correct answer
    D

    Store raw data and calculate aggregates when needed

    Explanation

    Keeping raw data preserves the ability to calculate new reports later, whereas storing only an aggregate loses detail.

  123. 123

    Why might precomputing an aggregate improve performance?

    1. A

      A simple lookup can replace an expensive repeated calculation

    2. B

      It guarantees that duplicate data never exists

    3. C

      It makes all joins unnecessary in every query

    4. D

      It prevents the underlying data from changing

    Correct answer
    A

    A simple lookup can replace an expensive repeated calculation

    Explanation

    A stored count or total can be retrieved quickly, but it creates a consistency risk because the precomputed value must remain synchronized.

Question 1 of 123
Question 1 of 123

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent