1. Home
  2. Explore
  3. Computer Science
  4. SQL Full Course Tutorial

Study methods

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

SQL Full Course Tutorial

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

What does SQL stand for?

39 questions

  1. 1

    What does SQL stand for?

    1. A

      Sequential Query Language

    2. B

      Standard Query Language

    3. C

      Simple Query Language

    4. D

      Structured Query Language

    Correct answer
    D

    Structured Query Language

    Explanation

    SQL stands for Structured Query Language, used to communicate with databases.

  2. 2

    Which CRUD operation corresponds to the SELECT keyword?

    1. A

      Create

    2. B

      Read

    3. C

      Update

    4. D

      Delete

    Correct answer
    B

    Read

    Explanation

    SELECT is used to retrieve data, which is the Read operation in CRUD.

  3. 3

    What type of SQL command is INSERT INTO?

    1. A

      DCL (Data Control Language)

    2. B

      DQL (Data Query Language)

    3. C

      DDL (Data Definition Language)

    4. D

      DML (Data Manipulation Language)

    Correct answer
    D

    DML (Data Manipulation Language)

    Explanation

    INSERT INTO is a DML command used to add data to existing tables.

  4. 4

    Which of the following is a characteristic of a data warehouse according to Bill Inmon?

    1. A

      Subject-oriented

    2. B

      Volatile

    3. C

      Real-time

    4. D

      Application-oriented

    Correct answer
    A

    Subject-oriented

    Explanation

    A data warehouse must be subject-oriented, non-volatile, integrated, and time-variant.

  5. 5

    In an ERD, what does the 'crow's foot' symbol indicate?

    1. A

      Many-to-many relationship

    2. B

      Zero or one relationship

    3. C

      One-to-one relationship

    4. D

      One-to-many relationship

    Correct answer
    D

    One-to-many relationship

    Explanation

    The crow's foot symbol on a line in an ERD indicates a 'many' side, typically one-to-many relationship.

  6. 6

    What is the purpose of a primary key in a table?

    1. A

      Link to another table

    2. B

      Uniquely identify each row

    3. C

      Store large data

    4. D

      Speed up queries

    Correct answer
    B

    Uniquely identify each row

    Explanation

    A primary key uniquely identifies each row in a table.

  7. 7

    Which SQL clause is used to filter rows before aggregation?

    1. A

      GROUP BY

    2. B

      WHERE

    3. C

      HAVING

    4. D

      ORDER BY

    Correct answer
    B

    WHERE

    Explanation

    WHERE filters rows before aggregation occurs.

  8. 8

    What does the DISTINCT keyword do in a SELECT statement?

    1. A

      Limits the number of rows returned

    2. B

      Sorts the result in ascending order

    3. C

      Removes duplicate rows from the result

    4. D

      Filters rows based on a condition

    Correct answer
    C

    Removes duplicate rows from the result

    Explanation

    DISTINCT returns only unique rows, removing duplicates.

  9. 9

    Which wildcard character in SQL matches zero or more characters?

    1. A

      ?

    2. B

      %

    3. C
    4. D

      _

    Correct answer
    B

    %

    Explanation

    The percent sign (%) matches any sequence of zero or more characters in a LIKE pattern.

  10. 10

    What is the result of the expression 11 % 3?

    1. A

      0

    2. B

      2

    3. C

      3

    4. D

      1

    Correct answer
    B

    2

    Explanation

    The modulus operator returns the remainder: 11 divided by 3 is 3 remainder 2.

  11. 11

    Which aggregate function returns the most frequently occurring value?

    1. A

      MODE

    2. B

      MEDIAN

    3. C

      AVG

    4. D

      There is no built-in mode function

    Correct answer
    D

    There is no built-in mode function

    Explanation

    SQL does not have a built-in MODE function; such calculations require additional logic.

  12. 12

    In a LEFT JOIN, which table's rows are all preserved?

    1. A

      The left table (table A)

    2. B

      Both tables

    3. C

      Neither table

    4. D

      The right table (table B)

    Correct answer
    A

    The left table (table A)

    Explanation

    A LEFT JOIN preserves all rows from the left table (table A) and matches rows from the right table.

  13. 13

    What is a self-join?

    1. A

      Joining with an alias

    2. B

      Joining a table to itself

    3. C

      Joining two identical tables

    4. D

      Joining with no condition

    Correct answer
    B

    Joining a table to itself

    Explanation

    A self-join joins a table to itself, often using different aliases.

  14. 14

    Which SQL command is used to delete all rows from a table but keep the table structure?

    1. A

      DELETE TABLE

    2. B

      TRUNCATE TABLE

    3. C

      REMOVE TABLE

    4. D

      DROP TABLE

    Correct answer
    B

    TRUNCATE TABLE

    Explanation

    TRUNCATE TABLE removes all rows while preserving the table structure.

  15. 15

    What does the ALTER TABLE command do?

    1. A

      Deletes a table

    2. B

      Alters the data in a table

    3. C

      Creates a new table

    4. D

      Modifies the structure of an existing table

    Correct answer
    D

    Modifies the structure of an existing table

    Explanation

    ALTER TABLE is used to add, drop, or modify columns in an existing table.

  16. 16

    Which of the following is a DDL command?

    1. A

      UPDATE

    2. B

      DROP TABLE

    3. C

      DELETE

    4. D

      INSERT INTO

    Correct answer
    B

    DROP TABLE

    Explanation

    DROP TABLE is a DDL command that removes a table structure and data.

  17. 17

    What does the COALESCE function do?

    1. A

      Checks if any value is null

    2. B

      Replaces null with a specified default

    3. C

      Returns the first non-null value in a list of expressions

    4. D

      Returns the last non-null value

    Correct answer
    C

    Returns the first non-null value in a list of expressions

    Explanation

    COALESCE returns the first non-null value among its arguments.

  18. 18

    What is the difference between UNION and UNION ALL?

    1. A

      UNION ALL is faster but only works with numeric data

    2. B

      UNION ALL removes duplicates; UNION keeps duplicates

    3. C

      UNION sorts results; UNION ALL does not

    4. D

      UNION removes duplicates; UNION ALL keeps duplicates

    Correct answer
    D

    UNION removes duplicates; UNION ALL keeps duplicates

    Explanation

    UNION eliminates duplicate rows while UNION ALL retains all rows including duplicates.

  19. 19

    In a window function, what does the PARTITION BY clause do?

    1. A

      Divides rows into groups to which the function is applied separately

    2. B

      Filters partitions based on a condition

    3. C

      Orders rows within each partition

    4. D

      Defines the window frame

    Correct answer
    A

    Divides rows into groups to which the function is applied separately

    Explanation

    PARTITION BY splits the result set into partitions, and the window function is applied to each partition individually.

  20. 20

    Which function is used to extract a specific part of a date, such as month or year?

    1. A

      CAST

    2. B

      EXTRACT

    3. C

      DATE_PART

    4. D

      DATE_TRUNC

    Correct answer
    B

    EXTRACT

    Explanation

    EXTRACT retrieves a specified part (like year, month) from a date/timestamp.

  21. 21

    What does the ROW_NUMBER() function do?

    1. A

      Assigns a dense rank without gaps

    2. B

      Assigns a rank with gaps for ties

    3. C

      Assigns a unique sequential integer to each row within a partition

    4. D

      Returns the number of rows in the result set

    Correct answer
    C

    Assigns a unique sequential integer to each row within a partition

    Explanation

    ROW_NUMBER() gives each row a unique number starting from 1 within each partition.

  22. 22

    In Git, what is the command to create a new branch and switch to it?

    1. A

      git checkout -b

    2. B

      git clone

    3. C

      git switch

    4. D

      git branch

    Correct answer
    A

    git checkout -b

    Explanation

    git checkout -b creates a new branch and switches to it. (git switch -c is newer but functionally similar.)

  23. 23

    What is a pull request (PR) used for in GitHub?

    1. A

      Pulling updates from a remote repository

    2. B

      Proposing changes to a repository for review

    3. C

      Pushing local changes to the remote

    4. D

      Requesting to pull the latest changes from main

    Correct answer
    B

    Proposing changes to a repository for review

    Explanation

    A pull request is a way to propose changes and request that they be merged into another branch.

  24. 24

    Which of the following is a case expression?

    1. A

      CASE WHEN condition THEN result END

    2. B

      CHOOSE(condition, result)

    3. C

      IF condition THEN result

    4. D

      SWITCH condition

    Correct answer
    A

    CASE WHEN condition THEN result END

    Explanation

    SQL uses CASE expression with WHEN-THEN-ELSE-END syntax.

  25. 25

    What type of join returns only rows where there is a match in both tables?

    1. A

      RIGHT JOIN

    2. B

      INNER JOIN

    3. C

      LEFT JOIN

    4. D

      FULL OUTER JOIN

    Correct answer
    B

    INNER JOIN

    Explanation

    INNER JOIN returns rows that have matching values in both tables.

  26. 26

    What is the purpose of the HAVING clause?

    1. A

      Filter groups after aggregation

    2. B

      Order the result set

    3. C

      Filter rows before grouping

    4. D

      Limit the number of groups

    Correct answer
    A

    Filter groups after aggregation

    Explanation

    HAVING is used to filter groups created by GROUP BY, not individual rows.

  27. 27

    Which command is used to initialize a Git repository in a project folder?

    1. A

      git start

    2. B

      git init

    3. C

      git new

    4. D

      git create

    Correct answer
    B

    git init

    Explanation

    git init creates a new Git repository in the current directory.

  28. 28

    What does the 'CASCADE' option in a DROP SCHEMA command do?

    1. A

      Drops only the schema if empty

    2. B

      Cascades the drop to other databases

    3. C

      Drops the schema and all dependent objects

    4. D

      Reverts the drop if it fails

    Correct answer
    C

    Drops the schema and all dependent objects

    Explanation

    CASCADE ensures that the schema and all objects within it (like tables) are dropped.

  29. 29

    What is a CTE (Common Table Expression)?

    1. A

      A stored procedure that returns a table

    2. B

      A permanent table created by a SELECT INTO statement

    3. C

      A temporary named result set that exists within the scope of a single query

    4. D

      A subquery in the FROM clause

    Correct answer
    C

    A temporary named result set that exists within the scope of a single query

    Explanation

    A CTE is defined using WITH and provides a temporary result set that can be referenced in the main query.

  30. 30

    In the terminal, what command lists files and directories in the current directory?

    1. A

      list

    2. B

      ls

    3. C

      show

    4. D

      dir

    Correct answer
    B

    ls

    Explanation

    The 'ls' command lists contents of a directory on Unix-based systems.

  31. 31

    What is the default branch name in Git after a fresh 'git init'?

    1. A

      main

    2. B

      master

    3. C

      trunk

    4. D

      default

    Correct answer
    B

    master

    Explanation

    Historically, the default branch is named 'master'. Many platforms now use 'main' by default, but git init still creates 'master' unless configured otherwise.

  32. 32

    Which SQL function is used to round a numeric value to a specified number of decimal places?

    1. A

      TRUNC

    2. B

      CEIL

    3. C

      ROUND

    4. D

      FLOOR

    Correct answer
    C

    ROUND

    Explanation

    ROUND rounds a number to the specified decimal places.

  33. 33

    What does the NULLIF function do?

    1. A

      Returns NULL if the expression is NULL, otherwise the expression

    2. B

      Checks if a value is NULL

    3. C

      Replaces NULL with a default value

    4. D

      Returns NULL if two expressions are equal, otherwise returns the first expression

    Correct answer
    D

    Returns NULL if two expressions are equal, otherwise returns the first expression

    Explanation

    NULLIF(expr1, expr2) returns NULL if expr1 equals expr2, else returns expr1.

  34. 34

    What is the purpose of a bridge table in a data warehouse?

    1. A

      To provide a flat view of the data

    2. B

      To resolve a many-to-many relationship between two tables

    3. C

      To enforce referential integrity

    4. D

      To store historical changes

    Correct answer
    B

    To resolve a many-to-many relationship between two tables

    Explanation

    A bridge table sits between two tables with a many-to-many relationship, containing foreign keys from both.

  35. 35

    Which of the following best describes a 'factless fact table'?

    1. A

      A table that only contains dates

    2. B

      A fact table with all null measures

    3. C

      A dimension table with no attributes

    4. D

      A fact table containing no numeric measures, only foreign keys

    Correct answer
    D

    A fact table containing no numeric measures, only foreign keys

    Explanation

    A factless fact table records events but lacks measurable numeric columns; it contains only foreign keys.

  36. 36

    In DuckDB, what command is used to exit the interactive CLI?

    1. A

      .quit

    2. B

      END

    3. C

      quit

    4. D

      exit

    Correct answer
    A

    .quit

    Explanation

    The DuckDB CLI uses '.quit' to exit (or '.exit').

  37. 37

    What is the correct order of clauses in a SQL query (syntactically)?

    1. A

      FROM, SELECT, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT

    2. B

      WHERE, SELECT, FROM, GROUP BY, HAVING, ORDER BY, LIMIT

    3. C

      SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT

    4. D

      SELECT, FROM, GROUP BY, WHERE, HAVING, ORDER BY, LIMIT

    Correct answer
    C

    SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT

    Explanation

    The correct syntactic order is SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.

  38. 38

    Which statement about SQL's logical operator precedence is true?

    1. A

      All are evaluated left to right

    2. B

      AND is evaluated before OR, which is evaluated before NOT

    3. C

      NOT is evaluated before AND, which is evaluated before OR

    4. D

      OR is evaluated before AND

    Correct answer
    C

    NOT is evaluated before AND, which is evaluated before OR

    Explanation

    In SQL, NOT has highest precedence, then AND, then OR.

  39. 39

    What is the difference between CHAR and VARCHAR data types?

    1. A

      CHAR stores Unicode; VARCHAR stores ASCII

    2. B

      VARCHAR is fixed; CHAR is variable

    3. C

      CHAR is numeric; VARCHAR is text

    4. D

      CHAR has fixed length; VARCHAR has variable length

    Correct answer
    D

    CHAR has fixed length; VARCHAR has variable length

    Explanation

    CHAR(n) always uses n characters (padding with spaces), while VARCHAR(n) uses only as much space as needed.

Question 1 of 39
Question 1 of 39

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent