1. Home
  2. Explore
  3. Computer Science
  4. SQL Basics for Beginners

Study methods

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

SQL Basics for Beginners

  • 65Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Data and SQL

Which description best captures what data is and why it is useful?

65 questions

  1. 1

    Which description best captures what data is and why it is useful?

    1. A

      Data is a dedicated location for storing information.

    2. B

      Data is a command used to retrieve records from a table.

    3. C

      Data is a collection of decisions already made by a business.

    4. D

      Data consists of facts about something that can be examined for insight.

    Correct answer
    D

    Data consists of facts about something that can be examined for insight.

    Explanation

    Data consists of facts about something. Examining those facts can reveal insights that support better decisions.

  2. 2

    What is a database, according to the content?

    1. A

      A database is a query that selects records from several tables.

    2. B

      A database is a key that uniquely identifies a single record.

    3. C

      A database is a dedicated storage location where data can be managed and processed.

    4. D

      A database is a report that displays only summarized business results.

    Correct answer
    C

    A database is a dedicated storage location where data can be managed and processed.

    Explanation

    A database is a dedicated place to store data and supports its management, manipulation, analysis, and processing.

  3. 3

    How can analyzing customer attributes such as age, income, and buying habits help a business?

    1. A

      Businesses use data only to identify the names of their customers.

    2. B

      Businesses store data mainly to avoid making decisions about products.

    3. C

      Businesses analyze data so that databases can create profits without human decisions.

    4. D

      Businesses analyze data to gain insights that can improve decisions and efficiency.

    Correct answer
    D

    Businesses analyze data to gain insights that can improve decisions and efficiency.

    Explanation

    Businesses can use data-derived insights to improve decisions, profits, and efficiency.

  4. 4

    What is SQL?

    1. A

      SQL is a database that automatically stores every type of business data.

    2. B

      SQL is a key that connects a parent table to a child table.

    3. C

      SQL is a table format used to arrange customer records in rows.

    4. D

      SQL is a query language used to communicate with databases and act on data.

    Correct answer
    D

    SQL is a query language used to communicate with databases and act on data.

    Explanation

    SQL is a query language used to communicate with databases, retrieve data, and perform actions on it.

  5. 5

    What happens when a statement such as SELECT name FROM customers is sent to a database?

    1. A

      The database converts each query into a new table and deletes the original data.

    2. B

      The database processes the query and returns a result, such as the requested names.

    3. C

      The database changes every matching record before returning any result.

    4. D

      The database sends the query to each record, which independently produces a report.

    Correct answer
    B

    The database processes the query and returns a result, such as the requested names.

    Explanation

    A query is sent to the database system, which processes it and returns the requested output.

  6. 6

    Why is SQL useful in business intelligence work?

    1. A

      SQL is widely used to query and manipulate data, including in business intelligence work.

    2. B

      SQL is mainly a method for designing hardware that stores business information.

    3. C

      SQL is useful only for creating customer-facing websites and is rarely used with databases.

    4. D

      SQL is used only to describe relationships between tables, not to retrieve their data.

    Correct answer
    A

    SQL is widely used to query and manipulate data, including in business intelligence work.

    Explanation

    SQL is used to retrieve and manipulate data and is widely used with relational databases and business intelligence tools.

  7. 7

    In a table, what do rows and columns represent?

    1. A

      Rows represent records, while columns represent attributes describing those records.

    2. B

      Rows represent attributes, while columns represent complete records.

    3. C

      Rows represent databases, while columns represent relationships between databases.

    4. D

      Rows represent keys, while columns represent constraints on the table.

    Correct answer
    A

    Rows represent records, while columns represent attributes describing those records.

    Explanation

    The content describes rows as records and columns as attributes that describe those records.

  8. 8

    What role does a field or column play in a table?

    1. A

      A field is a command that removes all records but preserves a table.

    2. B

      A field is a relationship between a parent table and a child table.

    3. C

      A field is a location for stored attributes, such as a column for age or city.

    4. D

      A field is a complete record, while an attribute is a database name.

    Correct answer
    C

    A field is a location for stored attributes, such as a column for age or city.

    Explanation

    A field is the location where an attribute is stored; columns hold attributes such as name, age, or address.

  9. 9

    Which statement best describes a table in a relational database?

    1. A

      A table is a collection of unrelated databases with different structures.

    2. B

      A table is a structured set of records with a consistent set of typed attributes.

    3. C

      A table is a command that specifies the permissions for a database user.

    4. D

      A table is a query result that must contain only one row.

    Correct answer
    B

    A table is a structured set of records with a consistent set of typed attributes.

    Explanation

    A table is described as a structured set of data whose columns have consistent types and whose records are stored in rows.

  10. 10

    What is the main purpose of a primary key?

    1. A

      A primary key stores a description shared by every record.

    2. B

      A primary key uniquely identifies a record in its table.

    3. C

      A primary key specifies the maximum character length for a column.

    4. D

      A primary key indicates whether a relationship between tables is optional.

    Correct answer
    B

    A primary key uniquely identifies a record in its table.

    Explanation

    The content presents a primary key as a unique identifier for each record, such as an ID.

  11. 11

    Which property of a primary key lets it distinguish one record from another?

    1. A

      A primary key must contain the name of a related table.

    2. B

      A primary key is allowed to identify several records at once.

    3. C

      A primary key value cannot be duplicated among records in the table.

    4. D

      A primary key value must be identical in every record in the table.

    Correct answer
    C

    A primary key value cannot be duplicated among records in the table.

    Explanation

    A primary key must be unique to each record, so it cannot be duplicated.

  12. 12

    How does a foreign key connect two related tables?

    1. A

      A foreign key in a child table refers to a key in the parent table.

    2. B

      A foreign key uniquely identifies every database in the system.

    3. C

      A foreign key replaces the primary key in the parent table.

    4. D

      A foreign key stores the attributes that are missing from the parent table.

    Correct answer
    A

    A foreign key in a child table refers to a key in the parent table.

    Explanation

    A foreign key in the child table refers to a primary key in the parent table, linking the records.

  13. 13

    What does a NOT NULL constraint require?

    1. A

      NOT NULL requires that a column have a value rather than be left empty.

    2. B

      NOT NULL allows a column to contain only text values.

    3. C

      NOT NULL prevents a table from receiving any additional records.

    4. D

      NOT NULL requires that every row contain the value zero.

    Correct answer
    A

    NOT NULL requires that a column have a value rather than be left empty.

    Explanation

    NOT NULL prevents a column from being left empty when a record is entered.

  14. 14

    In the example table definition, which type pairing is appropriate for age and name?

    1. A

      Use a null type for age and a database type for a name.

    2. B

      Use an integer type for age and a variable-character type for a name.

    3. C

      Use a primary-key type for a name and a foreign-key type for an age.

    4. D

      Use an integer type for a name and a variable-character type for an age.

    Correct answer
    B

    Use an integer type for age and a variable-character type for a name.

    Explanation

    The example uses an integer type for values such as age and a variable-character type for string values such as a name.

  15. 15

    In the example, what does specifying VARCHAR(30) for a name indicate?

    1. A

      VARCHAR(30) specifies that a field must contain exactly 30 rows.

    2. B

      VARCHAR(30) specifies a fixed primary key with 30 unique values.

    3. C

      VARCHAR(30) specifies an integer field that can store 30 records.

    4. D

      VARCHAR(30) specifies a variable-character field with a capacity of 30 characters.

    Correct answer
    D

    VARCHAR(30) specifies a variable-character field with a capacity of 30 characters.

    Explanation

    The example defines a name as VARCHAR(30), using 30 as the specified character capacity.

  16. 16

    How does the example arrange for customer IDs to be generated automatically and identify records?

    1. A

      Make the name column auto-increment so it can identify each row.

    2. B

      Define an integer ID as a primary key and set it to auto-increment.

    3. C

      Make the age column a foreign key so its values increase automatically.

    4. D

      Make the city column the primary key and leave the ID unspecified.

    Correct answer
    B

    Define an integer ID as a primary key and set it to auto-increment.

    Explanation

    The example combines an integer ID, NOT NULL, auto-increment, and a primary-key declaration to make IDs automatically increase and identify records.

  17. 17

    What does a relationship between database tables represent?

    1. A

      A relationship represents a connection between tables in a database.

    2. B

      A relationship is a way to store all tables as one column.

    3. C

      A relationship is a rule that makes every column contain a unique value.

    4. D

      A relationship is a command that orders records by a selected column.

    Correct answer
    A

    A relationship represents a connection between tables in a database.

    Explanation

    A relationship describes a connection between tables, such as a customer table connected to a product table.

  18. 18

    In the customer-and-product example, which table is treated as the parent?

    1. A

      The table with fewer records is always the parent, regardless of the relationship.

    2. B

      The product table is the parent, and the customer table is the child in the example.

    3. C

      Both the customer and product tables must be child tables.

    4. D

      The customer table is the parent, and the product table is the child in the example.

    Correct answer
    D

    The customer table is the parent, and the product table is the child in the example.

    Explanation

    In the example, the customer table is treated as the parent and the product table as the child.

  19. 19

    How does the example use keys to represent a parent-child relationship?

    1. A

      The parent table's primary key can appear as a foreign-key column in the child table.

    2. B

      The child table's primary key must replace every column in the parent table.

    3. C

      The parent table's foreign key must be copied into every database.

    4. D

      The child table's columns are combined into the parent table's primary key.

    Correct answer
    A

    The parent table's primary key can appear as a foreign-key column in the child table.

    Explanation

    The parent table's primary key is placed as a column in the child table, where it acts as a foreign key.

  20. 20

    What does ordinality describe in a relationship between tables?

    1. A

      Ordinality indicates the order in which a query returns records.

    2. B

      Ordinality indicates whether a parent-child relationship is optional or required.

    3. C

      Ordinality indicates whether a key is an integer or a string.

    4. D

      Ordinality indicates how many columns are present in a table.

    Correct answer
    B

    Ordinality indicates whether a parent-child relationship is optional or required.

    Explanation

    Ordinality indicates whether the relationship between a parent and child is optional or required.

  21. 21

    In the relationship notation described, what do zero and a perpendicular line indicate?

    1. A

      Zero indicates a many-to-many relationship, while a perpendicular line indicates one-to-one.

    2. B

      Zero indicates a parent table, while a perpendicular line indicates a child table.

    3. C

      Zero indicates a required relationship, while a perpendicular line indicates an optional one.

    4. D

      Zero indicates an optional relationship, while a perpendicular line indicates a required one.

    Correct answer
    D

    Zero indicates an optional relationship, while a perpendicular line indicates a required one.

    Explanation

    The content explains that zero marks an optional relationship, whereas a perpendicular line indicates that the relationship is required.

  22. 22

    Which example illustrates an optional relationship?

    1. A

      A book must have an owner, but it need not have been written by anyone.

    2. B

      A book may have no author, although it must have several owners.

    3. C

      A book must have both an owner and a reader at all times.

    4. D

      A book may have no owner, although it must have been written by someone.

    Correct answer
    D

    A book may have no owner, although it must have been written by someone.

    Explanation

    The book-and-owner example shows that a book's relationship to an owner may be optional, while someone must have written the book.

  23. 23

    What does cardinality describe?

    1. A

      Cardinality describes how many commands are available in SQL.

    2. B

      Cardinality describes whether a relationship is optional or required.

    3. C

      Cardinality describes patterns such as one-to-one, one-to-many, and many-to-many.

    4. D

      Cardinality describes whether a database stores text or integer values.

    Correct answer
    C

    Cardinality describes patterns such as one-to-one, one-to-many, and many-to-many.

    Explanation

    Cardinality describes the number pattern of a child table's relationship to its parent, such as one-to-one, one-to-many, or many-to-many.

  24. 24

    What is the general purpose of data definition language (DDL)?

    1. A

      DDL is used to save or undo a transaction.

    2. B

      DDL is used to define database structures such as tables and databases.

    3. C

      DDL is used to assign or withdraw access privileges from users.

    4. D

      DDL is used mainly to retrieve selected rows from an existing table.

    Correct answer
    B

    DDL is used to define database structures such as tables and databases.

    Explanation

    DDL is used to define database structures such as databases and tables.

  25. 25

    Which command is used to create a database or table?

    1. A

      CREATE creates a database or table.

    2. B

      DROP creates a new database or table.

    3. C

      ALTER creates a new database or table.

    4. D

      TRUNCATE creates a new database or table.

    Correct answer
    A

    CREATE creates a database or table.

    Explanation

    The content identifies CREATE as the command used to create a database or table.

  26. 26

    What is the distinction between DROP and TRUNCATE described in the content?

    1. A

      DROP removes the table itself, while TRUNCATE removes its records but preserves the table.

    2. B

      DROP inserts records, while TRUNCATE updates selected records.

    3. C

      DROP changes a column, while TRUNCATE creates a replacement table.

    4. D

      DROP removes records only, while TRUNCATE removes the table structure.

    Correct answer
    A

    DROP removes the table itself, while TRUNCATE removes its records but preserves the table.

    Explanation

    DROP removes the table or database itself, while TRUNCATE removes its records but preserves the table structure.

  27. 27

    Which command is identified as being used to alter a table?

    1. A

      ALTER undoes the most recent transaction.

    2. B

      ALTER grants a user permission to access a database.

    3. C

      ALTER retrieves every row from a table.

    4. D

      ALTER changes a table or its structure.

    Correct answer
    D

    ALTER changes a table or its structure.

    Explanation

    ALTER is presented as a command for changing a table or its structure.

  28. 28

    According to the content, what is the comment command used for?

    1. A

      It adds comments to a data dictionary.

    2. B

      It removes every record from a table.

    3. C

      It assigns access privileges to a database user.

    4. D

      It returns the average value of a column.

    Correct answer
    A

    It adds comments to a data dictionary.

    Explanation

    The content identifies the comment command as a way to add comments to a data dictionary.

  29. 29

    What is the general purpose of data manipulation language (DML)?

    1. A

      DML is used only to grant and revoke user permissions.

    2. B

      DML is used to manipulate data in database tables.

    3. C

      DML is used only to specify transaction characteristics.

    4. D

      DML is used only to define the structure of a database.

    Correct answer
    B

    DML is used to manipulate data in database tables.

    Explanation

    DML is described as the language group used to manipulate data, including inserting, updating, and deleting records.

  30. 30

    Which command is used to add values to a table?

    1. A

      INSERT INTO orders a table by one of its columns.

    2. B

      INSERT INTO removes a selected record from a table.

    3. C

      INSERT INTO gives a user access to a database.

    4. D

      INSERT INTO adds values to a table.

    Correct answer
    D

    INSERT INTO adds values to a table.

    Explanation

    INSERT INTO is used to add values or records to a table.

  31. 31

    How do UPDATE and DELETE differ?

    1. A

      UPDATE creates a database, while DELETE creates a table.

    2. B

      UPDATE removes a table, while DELETE changes its column definitions.

    3. C

      UPDATE changes existing values, while DELETE removes records.

    4. D

      UPDATE grants permissions, while DELETE revokes permissions.

    Correct answer
    C

    UPDATE changes existing values, while DELETE removes records.

    Explanation

    UPDATE changes values in existing records, while DELETE removes records.

  32. 32

    What does SELECT * FROM table_name request?

    1. A

      SELECT queries data, and SELECT * requests all columns from the table.

    2. B

      SELECT defines a table, and SELECT * requests only its primary key.

    3. C

      SELECT sets a transaction point, and SELECT * commits the transaction.

    4. D

      SELECT removes data, and SELECT * removes every row in the table.

    Correct answer
    A

    SELECT queries data, and SELECT * requests all columns from the table.

    Explanation

    SELECT is used to query data, and SELECT * requests all columns from the specified table.

  33. 33

    Which statement about data control language (DCL) matches the content?

    1. A

      DCL includes INSERT and DELETE, which modify table records.

    2. B

      DCL includes CREATE and DROP, which define and remove tables.

    3. C

      DCL includes COMMIT and ROLLBACK, which manage transactions.

    4. D

      DCL includes GRANT and REVOKE, which give and withdraw user privileges.

    Correct answer
    D

    DCL includes GRANT and REVOKE, which give and withdraw user privileges.

    Explanation

    DCL includes GRANT and REVOKE, which give and withdraw user access privileges.

  34. 34

    Which set of commands belongs to transaction control language (TCL)?

    1. A

      TCL includes commands for creating and removing database tables.

    2. B

      TCL includes commands for granting and withdrawing user privileges.

    3. C

      TCL includes commands for selecting columns and filtering records.

    4. D

      TCL includes commands for committing, rolling back, and saving transaction points.

    Correct answer
    D

    TCL includes commands for committing, rolling back, and saving transaction points.

    Explanation

    TCL includes commands such as COMMIT, ROLLBACK, and SAVEPOINT for managing transactions.

  35. 35

    How do COMMIT and ROLLBACK differ in transaction control?

    1. A

      COMMIT grants access, while ROLLBACK removes a user's privileges.

    2. B

      COMMIT saves changes, while ROLLBACK undoes changes back to the previous commit.

    3. C

      COMMIT deletes a table, while ROLLBACK recreates its columns.

    4. D

      COMMIT selects records, while ROLLBACK orders them by a column.

    Correct answer
    B

    COMMIT saves changes, while ROLLBACK undoes changes back to the previous commit.

    Explanation

    The content describes COMMIT as saving transaction changes and ROLLBACK as returning to the previous commit after an error.

  36. 36

    What functions do SAVEPOINT and SET TRANSACTION serve?

    1. A

      SAVEPOINT marks a point in a transaction, and SET TRANSACTION specifies its characteristics.

    2. B

      SAVEPOINT creates a database, and SET TRANSACTION truncates its tables.

    3. C

      SAVEPOINT grants user privileges, and SET TRANSACTION revokes them.

    4. D

      SAVEPOINT permanently removes a transaction, and SET TRANSACTION selects table columns.

    Correct answer
    A

    SAVEPOINT marks a point in a transaction, and SET TRANSACTION specifies its characteristics.

    Explanation

    A SAVEPOINT marks a point in a transaction, and SET TRANSACTION specifies transaction characteristics.

  37. 37

    What does CRUD stand for?

    1. A

      CRUD stands for create, read, update, and delete.

    2. B

      CRUD stands for create, revise, undo, and deploy.

    3. C

      CRUD stands for control, read, update, and describe.

    4. D

      CRUD stands for connect, retrieve, use, and define.

    Correct answer
    A

    CRUD stands for create, read, update, and delete.

    Explanation

    CRUD stands for create, read, update, and delete—the basic operations that can be performed on data.

  38. 38

    How do SHOW DATABASES and USE differ in the setup example?

    1. A

      SHOW DATABASES creates a database, and USE removes it.

    2. B

      SHOW DATABASES lists databases, and USE selects one to work with.

    3. C

      SHOW DATABASES selects a database, and USE lists the tables in it.

    4. D

      SHOW DATABASES displays rows, and USE updates them.

    Correct answer
    B

    SHOW DATABASES lists databases, and USE selects one to work with.

    Explanation

    SHOW DATABASES displays available databases, and USE database_name selects one as the active database.

  39. 39

    Which sequence matches the database setup demonstrated?

    1. A

      Create the tables first, then use DROP to add them to a database.

    2. B

      Create the database, then use it before creating tables inside it.

    3. C

      Insert records first, then use CREATE DATABASE to store them.

    4. D

      Use the database name to create a table, then truncate the database.

    Correct answer
    B

    Create the database, then use it before creating tables inside it.

    Explanation

    The example creates a database with CREATE DATABASE and then selects it with USE before creating tables inside it.

  40. 40

    Which command is used in the example to define a table?

    1. A

      USE TABLE defines a new table and its columns.

    2. B

      SHOW TABLES defines a new table and its attributes.

    3. C

      INSERT INTO defines a new table and its attributes.

    4. D

      CREATE TABLE defines a new table and its attributes.

    Correct answer
    D

    CREATE TABLE defines a new table and its attributes.

    Explanation

    The example uses CREATE TABLE to define a table and its attributes.

  41. 41

    Why is AUTO_INCREMENT used for an ID column in the example?

    1. A

      AUTO_INCREMENT prevents new records from being inserted into the table.

    2. B

      AUTO_INCREMENT automatically increases the ID value for new records.

    3. C

      AUTO_INCREMENT copies the same ID into every new record.

    4. D

      AUTO_INCREMENT generates a random city value for each record.

    Correct answer
    B

    AUTO_INCREMENT automatically increases the ID value for new records.

    Explanation

    AUTO_INCREMENT generates increasing ID values as new records are inserted, avoiding the need to enter each ID manually.

  42. 42

    What punctuation marks the end of a query in the demonstrated MySQL interaction?

    1. A

      A comma marks the end of every SQL query in the example.

    2. B

      A quotation mark marks the end of every SQL query in the example.

    3. C

      A semicolon marks the end of a query in the example.

    4. D

      A closing parenthesis marks the end of every SQL query in the example.

    Correct answer
    C

    A semicolon marks the end of a query in the example.

    Explanation

    In the demonstrated MySQL interaction, a semicolon marks the end of a query.

  43. 43

    How does the demonstrated INSERT INTO statement specify where new values belong?

    1. A

      Name the rows to remove, then provide replacement column definitions.

    2. B

      Name a database and its keys, then provide a query result as a constraint.

    3. C

      Name the target table and columns, then provide values for those columns.

    4. D

      Name the user and permissions, then provide the table's transaction history.

    Correct answer
    C

    Name the target table and columns, then provide values for those columns.

    Explanation

    The INSERT INTO example names the table and the columns that will receive values, then supplies corresponding values.

  44. 44

    How are string and integer values entered in the demonstrated insert example?

    1. A

      Put string values in quotation marks and enter integer values as numbers.

    2. B

      Put both strings and integers in quotation marks in every case.

    3. C

      Enter both strings and integers without quotation marks in every case.

    4. D

      Put integer values in quotation marks and enter strings without quotation marks.

    Correct answer
    A

    Put string values in quotation marks and enter integer values as numbers.

    Explanation

    The example puts string values such as names and cities in quotation marks, while integer values are entered as numbers.

  45. 45

    Which command is used in the example to check which tables have been created?

    1. A

      SHOW TABLES lists the tables in the selected database.

    2. B

      SHOW DATABASES displays the records inside the currently selected table.

    3. C

      SELECT TABLES checks whether a new column has been created.

    4. D

      USE TABLES displays all databases on the server.

    Correct answer
    A

    SHOW TABLES lists the tables in the selected database.

    Explanation

    SHOW TABLES is used after table creation to check which tables exist in the selected database.

  46. 46

    How does selecting * differ from selecting specific column names?

    1. A

      SELECT * deletes all columns, while named columns recreate selected ones.

    2. B

      SELECT * requests all rows from all tables, while named columns request one row.

    3. C

      SELECT * requests only the primary key, while named columns request every column.

    4. D

      SELECT * requests all columns, while named columns restrict the returned columns.

    Correct answer
    D

    SELECT * requests all columns, while named columns restrict the returned columns.

    Explanation

    SELECT * requests all columns, while a list such as SELECT name, age requests only those named columns.

  47. 47

    What is the purpose of a WHERE clause?

    1. A

      A WHERE clause defines the data type of each column.

    2. B

      A WHERE clause filters records to match a condition.

    3. C

      A WHERE clause grants database access to a user.

    4. D

      A WHERE clause adds a new table to the database.

    Correct answer
    B

    A WHERE clause filters records to match a condition.

    Explanation

    A WHERE clause filters records according to a condition, allowing the query to target specific rows.

  48. 48

    What does a condition such as WHERE city = 'Mumbai' do?

    1. A

      It sorts all records alphabetically by city.

    2. B

      It changes the city value in every record to Mumbai.

    3. C

      It selects every record except those whose city is Mumbai.

    4. D

      It selects records whose city value equals Mumbai.

    Correct answer
    D

    It selects records whose city value equals Mumbai.

    Explanation

    The example WHERE city = 'Mumbai' selects records whose city value matches Mumbai.

  49. 49

    In the example query, what is the effect of using AND between city and product conditions?

    1. A

      AND returns records that satisfy either of two conditions.

    2. B

      AND requires records to satisfy both specified conditions.

    3. C

      AND combines two columns into a single result column.

    4. D

      AND sorts records by the first condition and ignores the second.

    Correct answer
    B

    AND requires records to satisfy both specified conditions.

    Explanation

    The example combines conditions with AND to find records satisfying both the city condition and the product condition.

  50. 50

    What does ORDER BY income do when no sort direction is specified?

    1. A

      ORDER BY income calculates the total income of all records.

    2. B

      ORDER BY income filters out records that have no income.

    3. C

      ORDER BY income changes every income value to the same amount.

    4. D

      ORDER BY income sorts records by income, ascending by default.

    Correct answer
    D

    ORDER BY income sorts records by income, ascending by default.

    Explanation

    The example uses ORDER BY income to sort records by income, and ascending order is the default when no direction is specified.

  51. 51

    What does adding DESC to an ordering request do?

    1. A

      DESC calculates the difference between the largest and smallest values.

    2. B

      DESC sorts values from lowest to highest.

    3. C

      DESC sorts values from highest to lowest.

    4. D

      DESC removes duplicate values from the results.

    Correct answer
    C

    DESC sorts values from highest to lowest.

    Explanation

    The content explains that DESC orders results in descending order, placing larger values such as higher incomes first.

  52. 52

    What does DISTINCT do in a query?

    1. A

      DISTINCT returns unique values without repeating duplicates.

    2. B

      DISTINCT updates repeated values to make them identical.

    3. C

      DISTINCT returns every occurrence of each value, including duplicates.

    4. D

      DISTINCT sorts values from highest to lowest.

    Correct answer
    A

    DISTINCT returns unique values without repeating duplicates.

    Explanation

    DISTINCT is used to return unique values, such as customer names, without repeating duplicates.

  53. 53

    What does SUM(income) calculate?

    1. A

      SUM(income) returns the smallest income value.

    2. B

      SUM(income) adds the income values together.

    3. C

      SUM(income) returns the average income value.

    4. D

      SUM(income) counts the records with an income value.

    Correct answer
    B

    SUM(income) adds the income values together.

    Explanation

    The example uses SUM(income) to calculate the total income for the records included in the query.

  54. 54

    What does AVG(income) return?

    1. A

      AVG(income) counts all records in the table.

    2. B

      AVG(income) adds all income values without averaging them.

    3. C

      AVG(income) returns the largest income value.

    4. D

      AVG(income) calculates the average income value.

    Correct answer
    D

    AVG(income) calculates the average income value.

    Explanation

    AVG(income) calculates the average of the income values included in the query.

  55. 55

    How do MAX and MIN differ when applied to a column?

    1. A

      MAX finds the smallest value, while MIN finds the largest value.

    2. B

      MAX removes duplicates, while MIN orders them.

    3. C

      MAX finds the largest value, while MIN finds the smallest value.

    4. D

      MAX counts values, while MIN averages them.

    Correct answer
    C

    MAX finds the largest value, while MIN finds the smallest value.

    Explanation

    The examples use MAX to find the largest value and MIN to find the smallest value in a column.

  56. 56

    Why does the example recommend counting a field that is not null?

    1. A

      COUNT sums field values, so the field should contain only integers.

    2. B

      COUNT counts records through a field, so a non-null field avoids missing-value issues.

    3. C

      COUNT sorts records, so the field should contain dates.

    4. D

      COUNT returns unique values, so the field should contain duplicates.

    Correct answer
    B

    COUNT counts records through a field, so a non-null field avoids missing-value issues.

    Explanation

    The example uses COUNT to count records through a chosen field and notes that a field that is not null is preferable because null values may not be counted.

  57. 57

    What happens when an aggregate query includes a WHERE condition on product?

    1. A

      A WHERE clause with an aggregate limits the calculation to records that match its condition.

    2. B

      A WHERE clause with an aggregate applies only after the results are sorted.

    3. C

      A WHERE clause with an aggregate always changes the underlying values.

    4. D

      A WHERE clause with an aggregate prevents the query from returning a result.

    Correct answer
    A

    A WHERE clause with an aggregate limits the calculation to records that match its condition.

    Explanation

    Using WHERE with an aggregate, such as SUM(income) for customers who bought a phone, restricts the aggregate to matching records.

  58. 58

    Which distinction between UPDATE and ALTER matches the content?

    1. A

      UPDATE changes record values, while ALTER changes a table or its structure.

    2. B

      UPDATE removes all records, while ALTER restores them.

    3. C

      UPDATE changes the table structure, while ALTER changes selected record values.

    4. D

      UPDATE grants permissions, while ALTER selects records.

    Correct answer
    A

    UPDATE changes record values, while ALTER changes a table or its structure.

    Explanation

    The content distinguishes UPDATE, which changes values in selected records, from ALTER, which changes a table or its structure.

  59. 59

    How can an UPDATE statement target a particular record rather than changing every record?

    1. A

      Use DISTINCT to identify the records whose values should change.

    2. B

      Use CREATE TABLE to identify the records whose values should change.

    3. C

      Use a WHERE condition to target the records whose values should change.

    4. D

      Use ORDER BY to identify the records whose values should change.

    Correct answer
    C

    Use a WHERE condition to target the records whose values should change.

    Explanation

    An UPDATE statement uses a WHERE condition to target the records whose values should change.

  60. 60

    How does DELETE differ from TRUNCATE as described in the content?

    1. A

      DELETE can remove records, while TRUNCATE removes all records but preserves the table.

    2. B

      DELETE changes selected values, while TRUNCATE changes the data types.

    3. C

      DELETE creates a fresh table, while TRUNCATE changes its name.

    4. D

      DELETE removes the table structure, while TRUNCATE removes only one column.

    Correct answer
    A

    DELETE can remove records, while TRUNCATE removes all records but preserves the table.

    Explanation

    DELETE removes records, while TRUNCATE removes all records from a table but leaves the table itself in place.

  61. 61

    What relationship does the example's foreign-key constraint establish?

    1. A

      It makes every product record a new customer record.

    2. B

      It makes customer_id an independent primary key unrelated to customers.

    3. C

      It links product records to customer records through a referenced customer key.

    4. D

      It makes the customer table depend on product names rather than customer IDs.

    Correct answer
    C

    It links product records to customer records through a referenced customer key.

    Explanation

    The example defines customer_id in the product table as a foreign key referencing the customer table, linking product records to existing customers.

  62. 62

    Why does the example's insert fail when it uses a customer ID that is not present in the customer table?

    1. A

      It automatically creates a matching customer for every product record.

    2. B

      It prevents a product record from referring to a nonexistent customer ID.

    3. C

      It changes a product's ID to match the customer's ID.

    4. D

      It prevents product records from containing names.

    Correct answer
    B

    It prevents a product record from referring to a nonexistent customer ID.

    Explanation

    The example's foreign-key constraint rejects a product record whose customer_id does not match an existing customer record.

  63. 63

    Why would a query use a join between customer and product tables?

    1. A

      A join changes all columns in two tables to the same data type.

    2. B

      A join combines related data from multiple tables in one query result.

    3. C

      A join assigns a primary key to every database in the system.

    4. D

      A join deletes records that are shared by multiple tables.

    Correct answer
    B

    A join combines related data from multiple tables in one query result.

    Explanation

    A join lets a query retrieve fields from two tables, such as customer details from one table and product details from another.

  64. 64

    Why does the join example qualify fields with table names, such as customer.name?

    1. A

      Table-qualified field names create new columns in the joined result.

    2. B

      Table-qualified field names identify which table supplies each selected field.

    3. C

      Table names are used to convert all selected values to strings.

    4. D

      Table names are used only to specify which records should be deleted.

    Correct answer
    B

    Table-qualified field names identify which table supplies each selected field.

    Explanation

    The join example uses table-qualified references such as customer.name and product_model.price to specify which table supplies each field.

  65. 65

    What condition allows the demonstrated join to connect customer and product-model records?

    1. A

      The tables are joined by sorting both tables by their prices.

    2. B

      The tables are joined by matching every customer field to every product field.

    3. C

      The tables are joined by matching the related key fields.

    4. D

      The tables are joined by requiring their names to be identical.

    Correct answer
    C

    The tables are joined by matching the related key fields.

    Explanation

    The example joins customer and product-model information using a condition that connects their related IDs.

Question 1 of 65
Question 1 of 65

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent