SQL Fundamentals
- 123Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is SQL primarily used for?
What is SQL primarily used for?
123 questions
- 1
What is SQL primarily used for?
- A
Designing visual layouts for web applications
- B
Compiling source code into executable programs
- C
Managing network connections between web browsers
- D
Communicating with databases to store and retrieve data
Correct answer
DCommunicating 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.
- A
- 2
Why is SQL useful to developers who primarily use another programming language?
- A
Most web applications use SQL alongside their backend programming language
- B
SQL converts programs written in one language into another language
- C
SQL is required only when developing browser-based user interfaces
- D
SQL automatically replaces the need for all backend programming languages
Correct answer
AMost 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.
- A
- 3
What does a database primarily provide?
- A
Software for organizing and storing large amounts of data
- B
A compiler that translates SQL into machine instructions
- C
A programming language for building graphical interfaces
- D
A network protocol for transferring files between computers
Correct answer
ASoftware 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.
- A
- 4
How does using SQL differ from manually using a spreadsheet?
- A
SQL stores data only as images instead of rows and columns
- B
SQL requires every value to be entered by clicking a cell
- C
SQL prevents users from changing stored information
- D
SQL uses code to automate database operations
Correct answer
DSQL uses code to automate database operations
Explanation
Spreadsheets are often manipulated manually, whereas SQL lets developers write code that automates database operations.
- A
- 5
Which set of operations is represented by CRUD?
- A
Copy, replace, undo, and deploy
- B
Compile, run, upload, and download
- C
Create, read, update, and delete
- D
Connect, render, execute, and debug
Correct answer
CCreate, read, update, and delete
Explanation
CRUD stands for create, read, update, and delete, the four basic operations performed on stored data.
- A
- 6
Which result does a SQL query normally produce?
- A
Console output containing only one text string
- B
A result set organized into rows and columns
- C
A compiled executable file for the database server
- D
A graphical spreadsheet that cannot be processed by code
Correct answer
BA result set organized into rows and columns
Explanation
SQL queries commonly return a result set formatted as a table containing rows and columns.
- A
- 7
Which statement about SQL keywords is generally correct?
- A
SQL keywords must match the capitalization of table names
- B
SQL keywords must always be written in lowercase
- C
SQL keywords are generally case insensitive
- D
SQL keywords are interpreted as strings unless quoted
Correct answer
CSQL keywords are generally case insensitive
Explanation
SQL is generally case insensitive, although uppercase keywords are commonly used as a readability convention.
- A
- 8
What is a SQL dialect?
- A
A programming language that replaces SQL entirely
- B
A database-specific variation of the common SQL language
- C
A special table containing multiple database schemas
- D
A method for translating SQL queries into spoken language
Correct answer
BA 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.
- A
- 9
Which statement retrieves every column from the users table?
- A
READ COLUMNS users; - B
SELECT * FROM users; - C
SELECT users FROM *; - D
GET ALL users;
Correct answer
BSELECT * FROM users;Explanation
The
*wildcard represents all columns, soSELECT * FROM users;returns every column from the users table. - A
- 10
Which query retrieves only the name and balance columns from users?
- A
SELECT name balance AS users; - B
SELECT name, balance FROM users; - C
GET name AND balance IN users; - D
SELECT users FROM name, balance;
Correct answer
BSELECT name, balance FROM users;Explanation
Multiple columns are listed after
SELECTand separated by commas. - A
- 11
What operation does a
SELECTstatement represent in CRUD?- A
A create operation
- B
A delete operation
- C
A read operation
- D
An update operation
Correct answer
CA read operation
Explanation
A
SELECTstatement reads data from a database, so it corresponds to the read operation in CRUD. - A
- 12
In SQLite, how are Boolean values represented when returned from a query?
- A
As binary data stored in a blob
- B
As floating-point values between −1 and 1
- C
As strings such as
trueandfalse - D
As integers such as 0 and 1
Correct answer
DAs integers such as 0 and 1
Explanation
SQLite accepts Boolean-like values but represents false and true as the integers 0 and 1 when returning data.
- A
- 13
Which SQL clause filters rows before any grouping or aggregation occurs?
- A
The
ORDER BYclause - B
The
LIMITclause - C
The
HAVINGclause - D
The
WHEREclause
Correct answer
DThe
WHEREclauseExplanation
The
WHEREclause filters individual rows before grouping and aggregation take place. - A
- 14
Which query returns users with administrative privileges?
- A
SELECT is_admin FROM users WHERE users = admin; - B
GET * FROM users HAVING admin = true; - C
SELECT users WHERE is_admin IS admin; - D
SELECT * FROM users WHERE is_admin = true;
Correct answer
DSELECT * FROM users WHERE is_admin = true;Explanation
The condition
is_admin = truefilters the users table to rows whose administrative flag is true. - A
- 15
What does the
*wildcard mean in aSELECTlist?- A
Return every table in the database
- B
Return only the primary-key column
- C
Return every column in the selected table
- D
Return only columns containing text
Correct answer
CReturn every column in the selected table
Explanation
In a
SELECTlist,*means all columns from the selected table or tables. - A
- 16
Which statement correctly describes the
INoperator?- A
It limits a result set to a fixed number of rows
- B
It combines every row from two unrelated tables
- C
It tests whether a value matches one of several listed values
- D
It converts a text value into an integer
Correct answer
CIt tests whether a value matches one of several listed values
Explanation
The
INoperator is shorthand for comparing a value against multiple possible values, such as country codes. - A
- 17
Which query selects users from the United States, Canada, or Mexico?
- A
SELECT * FROM users WHERE country_code BETWEEN ('US', 'CA', 'MX'); - B
SELECT * FROM users WHERE country_code CONTAINS ('US', 'CA', 'MX'); - C
SELECT * FROM users WHERE country_code LIKE ('US', 'CA', 'MX'); - D
SELECT * FROM users WHERE country_code IN ('US', 'CA', 'MX');
Correct answer
DSELECT * FROM users WHERE country_code IN ('US', 'CA', 'MX');Explanation
The
INoperator tests whethercountry_codematches any value in the supplied list. - A
- 18
How should SQL test whether a value is absent rather than equal to a normal value?
- A
Use
EQUALS EMPTYorNOT EMPTY - B
Use
MISSINGorPRESENT - C
Use
IS NULLorIS NOT NULL - D
Use
= NULLor!= NULL
Correct answer
CUse
IS NULLorIS NOT NULLExplanation
SQL uses the special syntax
IS NULLandIS NOT NULLbecause null represents the absence of a value. - A
- 19
What does a null value represent in SQL?
- A
The integer zero
- B
A text value with zero characters
- C
A Boolean value of false
- D
The absence of a value
Correct answer
DThe absence of a value
Explanation
Null indicates that no value is present. It is different from an empty string, zero, or false.
- A
- 20
What does
BETWEEN 13 AND 18test?- A
Whether a value is outside the specified range
- B
Whether a value lies within the specified range
- C
Whether a value contains the characters
13and18 - D
Whether a value matches either endpoint only
Correct answer
BWhether a value lies within the specified range
Explanation
The
BETWEENoperator checks whether a value is within the given lower and upper bounds. - A
- 21
What is the effect of placing
NOTbeforeBETWEEN?- A
It converts the range into a text pattern
- B
It selects only the two boundary values
- C
It selects values outside the specified range
- D
It removes null values from the result
Correct answer
CIt selects values outside the specified range
Explanation
A condition such as
NOT BETWEEN 10 AND 20matches values that are not within that range. - A
- 22
What does the percent wildcard represent in a
LIKEpattern?- A
Exactly one word
- B
Exactly one character
- C
Zero or more characters
- D
Only numeric characters
Correct answer
CZero or more characters
Explanation
In a
LIKEpattern,%matches zero or more characters. - A
- 23
Which pattern matches names that start with
Al?- A
'Al%' - B
'%Al' - C
'Al_' - D
'_Al_'
Correct answer
A'Al%'Explanation
The pattern
Al%requires the value to begin withAland permits any number of characters afterward. - A
- 24
What does the underscore wildcard represent in a
LIKEpattern?- A
Any number of numeric characters
- B
Exactly one character
- C
One or more words
- D
Zero or more characters
Correct answer
BExactly one character
Explanation
The underscore wildcard
_matches exactly one character. - A
- 25
Which pattern matches names that start with
Aland contain exactly five characters?- A
'%Al___' - B
'_Al__' - C
'Al%' - D
'Al___'
Correct answer
D'Al___'Explanation
The pattern contains
Alfollowed by exactly three underscore wildcards, producing five characters total. - A
- 26
Which query finds transaction notes containing the word
lunchanywhere?- A
SELECT * FROM transactions WHERE note IN '%lunch%'; - B
SELECT * FROM transactions WHERE note LIKE '%lunch%'; - C
SELECT * FROM transactions WHERE note BETWEEN '%lunch%'; - D
SELECT * FROM transactions WHERE note LIKE 'lunch';
Correct answer
BSELECT * FROM transactions WHERE note LIKE '%lunch%';Explanation
Percent signs on both sides of
lunchallow characters before and after the word. - A
- 27
What is the purpose of the
ANDlogical operator?- A
It requires exactly one condition to be true
- B
It combines two columns into one value
- C
It reverses the truth value of a condition
- D
It requires both conditions to be true
Correct answer
DIt requires both conditions to be true
Explanation
A condition joined with
ANDmatches only when both conditions evaluate to true. - A
- 28
What is the purpose of the
ORlogical operator?- A
It requires at least one condition to be true
- B
It requires exactly one condition to be true
- C
It requires both conditions to be false
- D
It removes conditions from the query
Correct answer
AIt requires at least one condition to be true
Explanation
ORmatches when at least one of its conditions is true; both conditions may also be true. - A
- 29
Why are parentheses useful in SQL conditions involving
ANDandOR?- A
They automatically create a new database table
- B
They convert all conditions into text comparisons
- C
They control the order in which conditions are evaluated
- D
They prevent the query from returning null values
Correct answer
CThey control the order in which conditions are evaluated
Explanation
Parentheses group conditions and determine which logical expressions are evaluated together first.
- A
- 30
Which operator tests equality in a SQL condition?
- A
A single equals sign,
= - B
A double equals sign,
== - C
The keyword
EQUALS - D
A triple equals sign,
===
Correct answer
AA single equals sign,
=Explanation
SQL uses a single equals sign for equality comparisons in conditions.
- A
- 31
What does the
LIMITclause do?- A
It limits a comparison to numeric values
- B
It prevents all future inserts into a table
- C
It caps the number of rows returned
- D
It restricts the number of columns in a table permanently
Correct answer
CIt caps the number of rows returned
Explanation
LIMITreturns no more than the specified number of rows. - A
- 32
Why might a developer use
LIMITwhen querying a production database?- A
To guarantee that exactly that many rows exist
- B
To avoid retrieving an excessively large result set
- C
To force the database to delete extra rows
- D
To make every query return at least that many rows
Correct answer
BTo 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.
- A
- 33
What happens if a query with
LIMIT 5naturally matches only two rows?- A
It returns two rows
- B
It creates three additional empty rows
- C
It produces an error because five rows are unavailable
- D
It returns exactly five rows with duplicates
Correct answer
AIt returns two rows
Explanation
LIMIT 5means no more than five rows, not exactly five rows. - A
- 34
What is the default sort direction for
ORDER BY?- A
Insertion order only
- B
Ascending order
- C
Descending order
- D
Random order
Correct answer
BAscending order
Explanation
Unless
DESCis specified,ORDER BYsorts values in ascending order. - A
- 35
Which query returns the largest transaction amounts first and only returns four rows?
- A
SELECT * FROM transactions ORDER BY amount DESC LIMIT 4; - B
SELECT * FROM transactions SORT amount DESC TAKE 4; - C
SELECT * FROM transactions ORDER BY amount ASC LIMIT 4; - D
SELECT * FROM transactions LIMIT 4 ORDER BY amount DESC;
Correct answer
ASELECT * FROM transactions ORDER BY amount DESC LIMIT 4;Explanation
The rows must be sorted with
ORDER BY amount DESCbefore the result is limited to four rows. - A
- 36
What does
DISTINCTdo in a query?- A
It removes duplicate values from the selected result
- B
It selects only rows containing null values
- C
It permanently removes duplicate rows from the table
- D
It sorts values from smallest to largest
Correct answer
AIt removes duplicate values from the selected result
Explanation
DISTINCTremoves repeated values from the query result, but it does not delete data from the underlying table. - A
- 37
Which query returns each country code only once?
- A
SELECT DISTINCT country_code FROM users; - B
SELECT UNIQUE ROW country_code FROM users; - C
SELECT country_code WITHOUT DUPLICATES users; - D
SELECT country_code GROUP users;
Correct answer
ASELECT DISTINCT country_code FROM users;Explanation
SELECT DISTINCT country_code FROM users;returns one result for each unique country code. - A
- 38
Which SQL statement inserts new rows into a table?
- A
The
INSERT INTOstatement - B
The
CREATE RECORDstatement - C
The
ADD ROWstatement - D
The
APPEND TABLEstatement
Correct answer
AThe
INSERT INTOstatementExplanation
INSERT INTOadds new records to an existing table. - A
- 39
Why must the order of values in an
INSERTstatement match the listed columns?- A
SQL accepts values only when columns are alphabetized
- B
Values are assigned randomly unless the columns are ordered
- C
The database ignores column names during insertion
- D
Each value is assigned to the column in the corresponding position
Correct answer
DEach 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.
- A
- 40
What does an auto-incrementing ID provide when inserting a new row?
- A
The database automatically encrypts every inserted value
- B
The database automatically creates a unique username
- C
The database automatically deletes the previous row
- D
The database automatically generates the next identifier
Correct answer
DThe 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.
- A
- 41
What is a UUID commonly used for?
- A
A randomly generated identifier for a record
- B
A query that returns multiple rows
- C
A password hashing algorithm
- D
A Boolean value stored in a database
Correct answer
AA randomly generated identifier for a record
Explanation
A UUID is a very large randomly generated identifier. Its many possible combinations make collisions extremely unlikely.
- A
- 42
Which SQL statement changes existing rows?
- A
The
MODIFY TABLEstatement - B
The
CHANGE RECORDstatement - C
The
ALTER VALUEstatement - D
The
UPDATEstatement
Correct answer
DThe
UPDATEstatementExplanation
The
UPDATEstatement changes values in existing rows, usually with aSETclause and a filteringWHEREclause. - A
- 43
Why should an
UPDATEstatement usually include a specificWHEREclause?- A
Without it, the query cannot identify the table
- B
Without it, SQL automatically converts values to null
- C
Without it, unintended rows may be updated
- D
Without it, only the primary key can be changed
Correct answer
CWithout it, unintended rows may be updated
Explanation
A missing or overly broad
WHEREclause can cause the update to affect many more rows than intended. - A
- 44
What does
DELETE FROM users;do when noWHEREclause is included?- A
It deletes only the first row in the users table
- B
It deletes the users table structure but keeps its rows
- C
It produces an error because deletion requires an ID
- D
It deletes every row in the users table
Correct answer
DIt deletes every row in the users table
Explanation
Without a
WHEREclause,DELETE FROM users;targets every row in the table. - A
- 45
Why is deleting by a primary key safer than deleting by a common name?
- A
Names are always stored as null values
- B
A primary key identifies one specific row
- C
Names cannot be used in SQL conditions
- D
Primary keys automatically create backups
Correct answer
BA primary key identifies one specific row
Explanation
A primary key is unique, whereas multiple records may share the same name.
- A
- 46
What is the purpose of
CREATE TABLE?- A
To retrieve rows from an existing table
- B
To rename a database server
- C
To create an index on an existing column
- D
To define a new table and its columns
Correct answer
DTo define a new table and its columns
Explanation
CREATE TABLEdefines a table name and the columns, data types, and constraints it contains. - A
- 47
What is a database schema?
- A
The structure describing how data is organized
- B
A backup copy of every row in a database
- C
A query result containing only primary keys
- D
A programming language used to access databases
Correct answer
AThe structure describing how data is organized
Explanation
A schema includes the tables, column names, data types, relationships, and constraints used to organize data.
- A
- 48
What is the difference between a row and a column in a table?
- A
A row represents a data type, while a column represents a database
- B
A row represents a constraint, while a column represents a backup
- C
A row represents a table, while a column represents a query
- D
A row represents a record, while a column represents an attribute
Correct answer
DA 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.
- A
- 49
Which SQLite data type is used for whole numbers that may be negative?
- A
Blob
- B
Integer
- C
Text
- D
Real
Correct answer
BInteger
Explanation
SQLite integers represent whole numbers, including negative values.
- A
- 50
Which SQLite data type is intended for numbers with fractional parts?
- A
Real
- B
Null
- C
Text
- D
Integer
Correct answer
AReal
Explanation
SQLite uses the real type for floating-point values or numbers with fractional parts.
- A
- 51
What is a blob typically used to store?
- A
A Boolean condition
- B
A database table name
- C
Large binary data
- D
A sequence of whole numbers only
Correct answer
CLarge binary data
Explanation
A blob stores binary data, such as raw file contents or other non-text data.
- A
- 52
Why might a database use
VARCHARinstead of a general text type?- A
The maximum length of the text is known
- B
The value must always be numeric
- C
The value must be stored as binary data
- D
The column is required to contain a primary key
Correct answer
AThe maximum length of the text is known
Explanation
A
VARCHARcan specify a maximum character length, allowing some database systems to make storage or performance optimizations. - A
- 53
What does a
NOT NULLconstraint prevent?- A
It prevents a query from returning text values
- B
It prevents a column from receiving duplicate values
- C
It prevents a table from having more than one row
- D
It prevents a column from receiving null values
Correct answer
DIt prevents a column from receiving null values
Explanation
A
NOT NULLconstraint requires a value to be present in the column for each inserted or updated row. - A
- 54
Which property does a primary key provide?
- A
Permission to store multiple identical rows
- B
Uniqueness and non-null identification of each row
- C
Automatic encryption of every column
- D
Automatic conversion of text into integers
Correct answer
BUniqueness and non-null identification of each row
Explanation
A primary key uniquely identifies each row and also cannot be null.
- A
- 55
How many primary keys can a table have?
- A
One primary key for every column
- B
Exactly two primary keys
- C
One primary key constraint
- D
An unlimited number of primary keys
Correct answer
COne 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.
- A
- 56
What does a
UNIQUEconstraint enforce?- A
Every row must contain a foreign key
- B
Every value must be a positive integer
- C
The column must also be the primary key
- D
No two non-null values in the constrained column may be identical
Correct answer
DNo 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.
- A
- 57
What is a foreign key?
- A
A query that joins unrelated databases
- B
A table that contains no primary key
- C
A column that stores encrypted passwords
- D
A column that references a key in another table
Correct answer
DA 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.
- A
- 58
What does a foreign key constraint help guarantee?
- A
The referenced record exists in the related table
- B
Every record in the table has the same name
- C
Every query using the table runs in constant time
- D
The related table contains no duplicate columns
Correct answer
AThe referenced record exists in the related table
Explanation
A foreign key constraint prevents references to nonexistent records in the related table.
- A
- 59
Which example represents a one-to-many relationship?
- A
One transaction can have exactly one database
- B
One column can have only one data type
- C
One country code can contain many characters
- D
One user can have many transactions
Correct answer
DOne user can have many transactions
Explanation
A user may be associated with zero or many transactions, which is a one-to-many relationship.
- A
- 60
Where is a foreign key usually placed in a one-to-many relationship?
- A
In a third table with no identifiers
- B
On the table representing the one side only
- C
In the database server configuration
- D
On the table representing the many side
Correct answer
DOn 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.
- A
- 61
How is a many-to-many relationship usually modeled?
- A
With a joining table containing identifiers from both entities
- B
With one text column containing all related records
- C
By duplicating the entire database for each relationship
- D
By placing every related record in the primary key
Correct answer
AWith 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.
- A
- 62
What is the primary purpose of a joining table?
- A
To store all metadata for one entity
- B
To model relationships between two entity tables
- C
To cache the result of every SQL query
- D
To replace every primary key in the database
Correct answer
BTo model relationships between two entity tables
Explanation
A joining table usually contains identifiers from two tables and represents the relationships between them.
- A
- 63
Why might a unique constraint cover two columns in a joining table?
- A
To make both columns independent primary keys
- B
To require both columns to contain text
- C
To ensure every entity has exactly two relationships
- D
To prevent the same relationship from being recorded twice
Correct answer
DTo 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.
- A
- 64
What is an inner join's defining behavior?
- A
It returns every row from both tables regardless of matches
- B
It returns only unmatched rows from the second table
- C
It returns rows with matching records in both tables
- D
It returns every row from the first table regardless of matches
Correct answer
CIt 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.
- A
- 65
What does a left join preserve?
- A
Every row from the left table
- B
Only rows that have no matching record
- C
Only rows present in both tables
- D
Every row from the right table
Correct answer
AEvery 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.
- A
- 66
What happens to right-table columns when a left join has no match?
- A
They contain null values
- B
They cause the entire query to fail
- C
They are filled with zeros
- D
They are copied from the left table
Correct answer
AThey contain null values
Explanation
When a left-table row has no matching right-table row, the right-table columns are returned as null.
- A
- 67
Why can a right join usually be replaced by a left join?
- A
Left joins automatically return every table
- B
The table order can be reversed
- C
Right joins never use matching conditions
- D
Right joins are identical to cross joins
Correct answer
BThe table order can be reversed
Explanation
Swapping the order of the tables and using a left join produces the equivalent result.
- A
- 68
What does a full join return?
- A
Only rows with a match in both tables
- B
Only rows that are missing from both tables
- C
All rows from both tables, matched when possible
- D
Every row from the left table only
Correct answer
CAll rows from both tables, matched when possible
Explanation
A full join preserves every row from both tables and fills unmatched columns with null values.
- A
- 69
What is the purpose of the
ONclause in a join?- A
It determines how many rows the query returns
- B
It defines the data type of every joined column
- C
It specifies how rows from the tables are related
- D
It sorts the joined result alphabetically
Correct answer
CIt specifies how rows from the tables are related
Explanation
The
ONclause provides the matching condition, such as one table's foreign key equaling another table's primary key. - A
- 70
Why are table-qualified names such as
users.iduseful?- A
They identify which table a column comes from
- B
They automatically create a table alias
- C
They prevent all null values in the result
- D
They convert a column into a primary key
Correct answer
AThey identify which table a column comes from
Explanation
Table-qualified names resolve ambiguity when multiple joined tables contain columns with the same name.
- A
- 71
What is a database migration?
- A
A method for changing a programming language
- B
A backup stored only in application memory
- C
An incremental change to a database schema
- D
A query that reads every row in a table
Correct answer
CAn 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.
- A
- 72
Why is adding a new table or column generally safer than removing one?
- A
Existing application code usually does not depend on the new resource
- B
New tables cannot contain constraints
- C
Removing data never affects application behavior
- D
New columns automatically repair all existing data
Correct answer
AExisting 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.
- A
- 73
What should generally happen first when removing a database column used by an application?
- A
Update the application code to stop using the column
- B
Add more queries that depend on the column
- C
Delete the production database immediately
- D
Create a second primary key for the column
Correct answer
AUpdate the application code to stop using the column
Explanation
The application should stop querying the resource before the database column is removed.
- A
- 74
Why are renaming migrations particularly difficult?
- A
SQL databases cannot store renamed tables
- B
Old and new application versions may expect different names
- C
Renaming always changes every stored value
- D
Renaming prevents all future inserts
Correct answer
BOld 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.
- A
- 75
What is an up migration?
- A
A migration that reverses the previous migration
- B
A migration that copies data into memory
- C
A migration that restores deleted user records
- D
A migration that moves the schema forward
Correct answer
DA migration that moves the schema forward
Explanation
Up migrations apply new schema changes and move the database toward a newer state.
- A
- 76
What is a down migration used for?
- A
Sorting rows in descending order
- B
Adding a foreign key automatically
- C
Creating a new production snapshot
- D
Rolling back a related schema change
Correct answer
DRolling back a related schema change
Explanation
A down migration reverses an earlier up migration, usually to recover from a problem.
- A
- 77
Which strategy is generally the safest for renaming a table when supported?
- A
Rename the table without changing any application code
- B
Delete the table and recreate it without copying data
- C
Alias the table so old and new code can reference it
- D
Run old and new code against unrelated tables permanently
Correct answer
CAlias 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.
- A
- 78
What is a database backup snapshot?
- A
A stored copy of the database at a particular time
- B
A temporary alias for a table name
- C
A live query that continuously changes the database
- D
A constraint that prevents data deletion
Correct answer
AA 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.
- A
- 79
What is the main limitation of taking only daily database snapshots?
- A
Snapshots prevent all future database writes
- B
Snapshots automatically duplicate every table forever
- C
Snapshots cannot be stored in cloud storage
- D
Data added after the latest snapshot may be lost
Correct answer
DData 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.
- A
- 80
How can more frequent snapshots reduce potential data loss?
- A
They eliminate the need for any database schema
- B
They shorten the interval of changes missing from the latest backup
- C
They prevent developers from deleting rows
- D
They guarantee that no backup will ever fail
Correct answer
BThey 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.
- A
- 81
What is an append-only log used for in a robust backup strategy?
- A
Replacing the production database during normal operation
- B
Deleting old records before each snapshot
- C
Recording database changes so they can be replayed
- D
Sorting all rows by their primary keys
Correct answer
CRecording 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.
- A
- 82
What is a soft delete?
- A
Deleting a row from a backup but not production
- B
Marking a row as deleted without physically removing it
- C
Removing a table name while preserving all queries
- D
Deleting a row only after asking for confirmation
Correct answer
BMarking a row as deleted without physically removing it
Explanation
A soft delete usually records a deletion marker, such as a
deleted_attimestamp, and filters marked rows from normal queries. - A
- 83
What is a disadvantage of soft deletes?
- A
They guarantee that large tables become faster
- B
They add application complexity and may create privacy concerns
- C
They remove the need for filtering in queries
- D
They make it impossible to recover deleted records
Correct answer
BThey 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.
- A
- 84
What does the
SUMaggregation return?- A
The total of numeric values in a column
- B
The average of all text values
- C
The largest numeric value in a column
- D
The number of rows in a table
Correct answer
AThe total of numeric values in a column
Explanation
SUMadds numeric values, such as transaction amounts. - A
- 85
What does the
COUNTaggregation return?- A
The alphabetically first text value
- B
The number of tables in a database server
- C
The total monetary value of a column
- D
The number of rows or values being counted
Correct answer
DThe number of rows or values being counted
Explanation
COUNTaggregates multiple rows into a count, such as the number of users or transactions. - A
- 86
What does the
MAXaggregation return?- A
The middle value in a sorted set
- B
The largest value in a set
- C
The number of values in a set
- D
The smallest value in a set
Correct answer
BThe largest value in a set
Explanation
MAXreturns the greatest value among the values being aggregated. - A
- 87
What does the
MINaggregation return?- A
The number of distinct tables in a set
- B
The largest value in a set
- C
The smallest value in a set
- D
The total of all values in a set
Correct answer
CThe smallest value in a set
Explanation
MINreturns the lowest value among the values being aggregated. - A
- 88
What does the
AVGaggregation do with null values?- A
It treats every null as the largest value
- B
It ignores null values when calculating the average
- C
It treats every null as the number zero
- D
It causes the entire query to return null
Correct answer
BIt ignores null values when calculating the average
Explanation
The average is calculated from values that exist; null values are excluded.
- A
- 89
What is the purpose of
GROUP BY?- A
To divide rows into groups for separate aggregation
- B
To remove all duplicate rows permanently
- C
To sort every row alphabetically
- D
To combine unrelated tables without a join
Correct answer
ATo divide rows into groups for separate aggregation
Explanation
GROUP BYcreates groups, allowing an aggregate such asSUMorCOUNTto be calculated separately for each group. - A
- 90
What is the difference between
WHEREandHAVING?- A
WHEREcreates tables, whileHAVINGdeletes tables - B
WHEREfilters rows before grouping, whileHAVINGfilters groups after aggregation - C
WHEREfilters groups after aggregation, whileHAVINGfilters columns before grouping - D
WHEREsorts rows, whileHAVINGlimits the number of rows
Correct answer
BWHEREfilters rows before grouping, whileHAVINGfilters groups after aggregationExplanation
WHEREapplies before grouping and aggregation.HAVINGapplies to the grouped results. - A
- 91
Which clause should filter groups whose transaction total exceeds $20?
- A
The
WHEREclause - B
The
LIMITclause - C
The
ORDER BYclause - D
The
HAVINGclause
Correct answer
DThe
HAVINGclauseExplanation
A transaction total is an aggregate result, so filtering it requires
HAVINGafter grouping. - A
- 92
Why is money often stored as an integer number of smaller units?
- A
Integer columns can store unlimited text values
- B
Integers automatically encrypt financial transactions
- C
Integer arithmetic avoids floating-point rounding problems
- D
Integers automatically calculate exchange rates
Correct answer
CInteger arithmetic avoids floating-point rounding problems
Explanation
Financial systems often store cents or pennies as integers because floating-point calculations can introduce rounding errors.
- A
- 93
What is an ORM?
- A
A network protocol used by web browsers
- B
A database backup format for cloud storage
- C
A SQL command that removes duplicate rows
- D
A library that maps application objects to database records
Correct answer
DA 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.
- A
- 94
What is a typical advantage of using an ORM?
- A
It eliminates the need to understand database schemas
- B
It gives more low-level control than raw SQL
- C
It makes common database operations less verbose
- D
It guarantees every query is faster
Correct answer
CIt 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.
- A
- 95
What trade-off does an ORM commonly make?
- A
It trades SQL compatibility for manual typing
- B
It trades some control for simplicity
- C
It trades data integrity for encryption
- D
It trades database storage for network bandwidth
Correct answer
BIt trades some control for simplicity
Explanation
ORMs simplify common operations but can obscure or limit direct control over the SQL being executed.
- A
- 96
How does a typical frontend communicate with a cloud-hosted database?
- A
The frontend sends HTTP requests to a backend, which uses SQL
- B
The frontend writes directly to database files in the cloud
- C
The database sends SQL directly to the user's browser
- D
The frontend replaces HTTP requests with spreadsheet commands
Correct answer
AThe 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.
- A
- 97
Which HTTP method commonly corresponds to a SQL read operation?
- A
POST
- B
PUT
- C
DELETE
- D
GET
Correct answer
DGET
Explanation
An HTTP
GETrequest commonly asks the backend to retrieve data, corresponding to a SQL read. - A
- 98
Which HTTP method commonly corresponds to creating a new database record?
- A
GET
- B
POST
- C
DELETE
- D
PUT
Correct answer
BPOST
Explanation
An HTTP
POSTrequest commonly creates a new resource, corresponding to an SQL insert. - A
- 99
What is SQL injection?
- A
A method for automatically indexing every database column
- B
A backup technique that stores queries in a log
- C
An attack that manipulates a query through unsafely inserted user input
- D
A process for converting SQL into a programming language
Correct answer
CAn 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.
- A
- 100
How should applications protect dynamic SQL values from SQL injection?
- A
Store every input as a table name
- B
Use parameterized queries or safe database-library interpolation
- C
Remove all
WHEREclauses from generated queries - D
Concatenate all user input directly into SQL strings
Correct answer
BUse 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.
- A
- 101
Why is ordinary string concatenation dangerous when constructing SQL?
- A
String concatenation changes every integer into a Boolean
- B
User input may be interpreted as executable SQL syntax
- C
String concatenation automatically deletes null values
- D
String concatenation prevents all database reads
Correct answer
BUser 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.
- A
- 102
What is the primary goal of database normalization?
- A
Reduce data redundancy and improve data integrity
- B
Guarantee that every query runs instantly
- C
Make every query use more duplicate data
- D
Replace all relational tables with JSON blobs
Correct answer
AReduce data redundancy and improve data integrity
Explanation
Normalization organizes data to reduce duplication and make stored information more consistent and reliable.
- A
- 103
What is the main rule of first normal form?
- A
Every table must contain exactly two columns
- B
Every relationship must be many-to-many
- C
Rows must be uniquely identifiable and tables must not be nested
- D
Every column must contain only integers
Correct answer
CRows 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.
- A
- 104
What additional dependency rule defines second normal form?
- A
Non-key columns must depend on the entire primary key
- B
Every table must have at least two primary keys
- C
All columns must contain unique values
- D
Every row must reference a different table
Correct answer
ANon-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.
- A
- 105
What rule is associated with third normal form?
- A
Non-key columns should depend only on the primary key
- B
Every table must avoid using integer values
- C
Every column must store a foreign key
- D
Every table must contain a composite primary key
Correct answer
ANon-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.
- A
- 106
What additional issue does Boyce-Codd normal form address?
- A
A primary-key column depending on a non-key column
- B
A database containing more than one table
- C
A table containing no text columns
- D
A query returning too few rows
Correct answer
AA 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.
- A
- 107
Which normal form represents the most normalized level among those discussed?
- A
First normal form
- B
Boyce-Codd normal form
- C
Second normal form
- D
Third normal form
Correct answer
BBoyce-Codd normal form
Explanation
Boyce-Codd normal form builds on the rules of first, second, and third normal form and adds an additional constraint.
- A
- 108
Why is storing a user's birthday generally better than storing only their age?
- A
A birthday automatically functions as a primary key
- B
Age cannot be calculated from a birthday
- C
Age becomes outdated over time, while the birthday remains stable
- D
Birthdays require less storage than every possible integer
Correct answer
CAge 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.
- A
- 109
What is data redundancy?
- A
A table containing a single primary key
- B
Unnecessary duplication of the same information
- C
A query that returns a calculated value
- D
A column containing a null value
Correct answer
BUnnecessary duplication of the same information
Explanation
Data redundancy occurs when the same information is stored in multiple places without a necessary reason.
- A
- 110
Why can duplicate data reduce data integrity?
- A
Duplicate data automatically converts values to null
- B
Duplicate data prevents all queries from running
- C
Duplicate data guarantees that every record is unique
- D
One copy may be updated while another remains outdated
Correct answer
DOne 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.
- A
- 111
When might denormalization be justified?
- A
Before the schema and relationships are understood
- B
Whenever developers want less accurate data
- C
When duplicate or precomputed data is needed to improve performance
- D
Whenever a database contains more than one table
Correct answer
CWhen 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.
- A
- 112
What is the recommended starting point for database design regarding normalization?
- A
Start normalized and denormalize only when necessary
- B
Avoid primary keys until performance becomes a problem
- C
Start fully denormalized and normalize after production failures
- D
Duplicate every frequently accessed value immediately
Correct answer
AStart normalized and denormalize only when necessary
Explanation
A normalized design generally improves correctness and maintainability; denormalization can be added later for demonstrated performance needs.
- A
- 113
What is a database index?
- A
An auxiliary structure that makes lookups faster
- B
A complete backup of every database table
- C
A list of every SQL keyword supported by a database
- D
A constraint that prevents all inserts
Correct answer
AAn auxiliary structure that makes lookups faster
Explanation
An index is an additional database structure, often based on a tree, that helps locate rows efficiently.
- A
- 114
What data structure commonly supports SQL index lookups?
- A
A plain text file without ordering
- B
A stack of unsorted values
- C
A circular queue
- D
A binary tree
Correct answer
DA binary tree
Explanation
SQL databases commonly use tree structures, such as binary-tree variants, to locate sorted values efficiently.
- A
- 115
What is the approximate lookup complexity of a balanced tree index?
- A
O(n2)
- B
O(1)
- C
O(n)
- D
O(logn)
Correct answer
DO(logn)
Explanation
A balanced tree can locate a value in approximately logarithmic time, O(logn), rather than scanning all n rows.
- A
- 116
Why should developers avoid indexing every column automatically?
- A
Indexes prevent the column from being queried
- B
Indexes store data only in temporary memory
- C
Indexes make primary keys non-unique
- D
Indexes consume memory and can slow inserts and updates
Correct answer
DIndexes 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.
- A
- 117
When is a single-column index especially useful?
- A
When a table contains no primary key
- B
When every row must contain a different table
- C
When a column is never referenced in queries
- D
When a column is frequently used for lookups
Correct answer
DWhen a column is frequently used for lookups
Explanation
A frequently queried column, such as an email used for login, may benefit from an index.
- A
- 118
How do indexes affect writes?
- A
They make every insert instantaneous
- B
They can slow writes because index structures must be updated
- C
They remove the need to store the inserted row
- D
They prevent updates to indexed columns
Correct answer
BThey can slow writes because index structures must be updated
Explanation
When data changes, associated index structures must also be updated, adding write overhead.
- A
- 119
What is a multi-column index designed to support?
- A
Storage of multiple unrelated tables in one column
- B
Lookups involving a specific combination of columns
- C
Queries that never use a
WHEREclause - D
Automatic conversion of all columns to text
Correct answer
BLookups involving a specific combination of columns
Explanation
A multi-column index is useful when queries commonly filter using a particular combination of fields.
- A
- 120
Why does the order of columns matter in a multi-column index?
- A
Column order determines whether values are nullable
- B
The database ignores all columns after the first
- C
Only the last column can be used in a lookup
- D
The index is ordered first by its leading column
Correct answer
DThe 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.
- A
- 121
Which query operation typically benefits from an index?
- A
Writing comments in application source code
- B
Filtering rows with a
WHEREcondition - C
Changing the database server's hostname
- D
Deleting an unused SQL keyword
Correct answer
BFiltering rows with a
WHEREconditionExplanation
Indexes are primarily used to speed up lookups, especially conditions such as
WHERE email = .... - A
- 122
Which statement about raw data and aggregations is generally recommended?
- A
Store every possible aggregate in a separate table
- B
Avoid storing data that may later be aggregated
- C
Store only aggregate results and discard the raw data
- D
Store raw data and calculate aggregates when needed
Correct answer
DStore 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.
- A
- 123
Why might precomputing an aggregate improve performance?
- A
A simple lookup can replace an expensive repeated calculation
- B
It guarantees that duplicate data never exists
- C
It makes all joins unnecessary in every query
- D
It prevents the underlying data from changing
Correct answer
AA 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.
- A

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