SQL Course Introduction
- 37Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is a database management system (DBMS)?
What is a database management system (DBMS)?
37 questions
- 1
What is a database management system (DBMS)?
- A
A language used to query and modify data in relational databases
- B
A software application used to manage databases and execute instructions
- C
A collection of data stored in a format that can be easily accessed
- D
A type of non-relational database that does not use tables
Correct answer
BA software application used to manage databases and execute instructions
Explanation
A DBMS is a software application that connects to databases, allows us to give instructions for querying or modifying data, and executes those instructions. It is not the data itself nor the language.
- A
- 2
What distinguishes relational databases from non-relational (NoSQL) databases?
- A
Relational databases cannot handle large amounts of data, unlike NoSQL databases
- B
Relational databases store data in tables linked by relationships, while NoSQL databases do not use tables or relationships
- C
Relational databases use SQL exclusively, while NoSQL databases use a different query language called NoSQL
- D
Relational databases are always open-source, while NoSQL databases are proprietary
Correct answer
BRelational databases store data in tables linked by relationships, while NoSQL databases do not use tables or relationships
Explanation
Relational databases store data in tables that are linked via relationships, which is why they are called relational. NoSQL databases do not have tables or relationships and have their own query languages.
- A
- 3
Why did SQL originally change its name from SEQUEL to SQL?
- A
Because SEQUEL was a trademark of an airplane company
- B
Because the developers wanted to align with other database languages
- C
Because SQL is easier to pronounce than SEQUEL
- D
Because SQL stands for Structured Query Language, which is more descriptive
Correct answer
ABecause SEQUEL was a trademark of an airplane company
Explanation
SQL was originally called SEQUEL (Structured English Query Language) but was changed to SQL because SEQUEL was a trademark of an airplane company.
- A
- 4
In MySQL Workbench, what does the 'Schemas' tab display?
- A
The databases available in the current database server
- B
The administrative tasks such as starting or stopping the server
- C
The SQL query results and output messages
- D
The list of stored procedures and functions
Correct answer
AThe databases available in the current database server
Explanation
The Schemas tab shows the databases that exist in the current database server. The Administration tab is for administrative tasks.
- A
- 5
What is the default port for MySQL server?
- A
3307
- B
8080
- C
3306
- D
5432
Correct answer
C3306
Explanation
The default port for MySQL server is 3306, as stated in the content when configuring the connection.
- A
- 6
Which of the following is NOT a valid clause in a SQL SELECT statement?
- A
HAVING
- B
FROM
- C
ORDER BY
- D
WHERE
Correct answer
AHAVING
Explanation
HAVING is used with GROUP BY, not directly in a basic SELECT statement. The basic clauses are SELECT, FROM, WHERE, and ORDER BY.
- A
- 7
What is the purpose of the asterisk (*) in a SELECT statement?
- A
It selects all rows from the table
- B
It selects only the primary key column
- C
It selects all columns from the specified table
- D
It selects the first column of the table
Correct answer
CIt selects all columns from the specified table
Explanation
The asterisk is a wildcard that returns all columns from the table. It is used to retrieve all columns without listing each one.
- A
- 8
How can you give a column a descriptive name in the result set?
- A
By using the RENAME keyword
- B
By using the ALIAS keyword
- C
By using the AS keyword followed by an alias
- D
By using the LABEL keyword
Correct answer
CBy using the AS keyword followed by an alias
Explanation
The AS keyword is used to rename a column or expression in the result set. For example, 'SELECT points AS discount_factor'.
- A
- 9
Which operator is used to remove duplicate values from a result set?
- A
DISTINCT
- B
DIFFERENT
- C
UNIQUE
- D
REMOVE DUPLICATES
Correct answer
ADISTINCT
Explanation
The DISTINCT keyword is used in a SELECT clause to return only unique values, eliminating duplicates.
- A
- 10
What does the WHERE clause do in a SQL query?
- A
It limits the number of rows returned
- B
It filters rows based on a condition
- C
It groups rows by a column
- D
It sorts the result set
Correct answer
BIt filters rows based on a condition
Explanation
The WHERE clause is used to filter records. Only rows that satisfy the condition are returned.
- A
- 11
Which comparison operator is used for 'not equal' in SQL?
- A
Both != and <>
- B
!=
- C
<>
- D
NOT EQUAL
Correct answer
ABoth != and <>
Explanation
In SQL, both '!=' and '<>' are valid operators for 'not equal'. The content mentions both.
- A
- 12
How should date values be enclosed in SQL?
- A
In single quotes
- B
In parentheses
- C
In double quotes only
- D
In square brackets
Correct answer
AIn single quotes
Explanation
Date values are enclosed in single quotes, even though they are not strings. The format is 'YYYY-MM-DD'.
- A
- 13
Which logical operator evaluates to true if both conditions are true?
- A
AND
- B
OR
- C
NOT
- D
XOR
Correct answer
AAND
Explanation
The AND operator returns true only when both conditions are true. OR returns true if at least one is true.
- A
- 14
What is the order of precedence for logical operators in SQL?
- A
NOT, OR, AND
- B
AND, OR, NOT
- C
OR, AND, NOT
- D
NOT, AND, OR
Correct answer
DNOT, AND, OR
Explanation
NOT has the highest precedence, followed by AND, then OR. Parentheses can override this order.
- A
- 15
Which operator is used to check if a value is within a list of values?
- A
BETWEEN
- B
IN
- C
IS
- D
LIKE
Correct answer
BIN
Explanation
The IN operator allows you to compare a column to a list of values. It is a shorter alternative to multiple OR conditions.
- A
- 16
What does the BETWEEN operator do?
- A
It checks if a value is strictly greater than the lower bound and strictly less than the upper bound
- B
It checks if a value is greater than or equal to the lower bound and less than or equal to the upper bound
- C
It checks if a value is between two values exclusively
- D
It checks if a value is equal to either the lower or upper bound only
Correct answer
BIt checks if a value is greater than or equal to the lower bound and less than or equal to the upper bound
Explanation
BETWEEN is inclusive, meaning it includes the boundary values. For example, 'BETWEEN 1000 AND 3000' includes 1000 and 3000.
- A
- 17
In the LIKE operator, what does the percent sign (%) represent?
- A
Exactly one character
- B
Any single character
- C
The beginning of a string
- D
Any number of characters (including zero)
Correct answer
DAny number of characters (including zero)
Explanation
The percent sign (%) matches any sequence of characters (including an empty string). The underscore (_) matches a single character.
- A
- 18
What does the '^' character mean in a MySQL regular expression?
- A
Logical OR
- B
Any single character
- C
End of string
- D
Beginning of string
Correct answer
DBeginning of string
Explanation
The caret (^) in a regular expression denotes the start of a string. The dollar sign ($) denotes the end.
- A
- 19
How do you find rows where a column has no value (NULL)?
- A
WHERE column EQUALS NULL
- B
WHERE column == NULL
- C
WHERE column = NULL
- D
WHERE column IS NULL
Correct answer
DWHERE column IS NULL
Explanation
NULL is not a value, so you cannot use equality operators. Use 'IS NULL' to check for nulls. 'IS NOT NULL' checks for non-null values.
- A
- 20
What is the default sort order in an ORDER BY clause?
- A
Random
- B
Descending (DESC)
- C
Alphabetical
- D
Ascending (ASC)
Correct answer
DAscending (ASC)
Explanation
The default sort order is ascending (ASC). You can specify DESC for descending order.
- A
- 21
Which clause is always placed at the end of a SELECT statement to limit the number of rows returned?
- A
TOP
- B
FETCH FIRST
- C
ROWNUM
- D
LIMIT
Correct answer
DLIMIT
Explanation
The LIMIT clause is used in MySQL to limit the number of rows. It must come after ORDER BY (if used).
- A
- 22
What does the following SQL statement do? SELECT * FROM orders LIMIT 6, 3
- A
It returns the first 6 rows, then the next 3 rows
- B
It returns 6 rows starting from row 3
- C
It skips the first 6 rows and returns the next 3 rows
- D
It returns rows 6 through 9
Correct answer
CIt skips the first 6 rows and returns the next 3 rows
Explanation
In MySQL LIMIT, the first number is the offset (rows to skip), and the second is the number of rows to return. So LIMIT 6, 3 skips 6 and returns 3.
- A
- 23
When joining two tables with an INNER JOIN, what rows are included in the result?
- A
All rows from the right table regardless of a match
- B
All rows from both tables, with NULLs where there is no match
- C
Only rows that have matching values in both tables
- D
All rows from the left table regardless of a match
Correct answer
COnly rows that have matching values in both tables
Explanation
An INNER JOIN returns only rows where the join condition is true. Rows without a match in either table are excluded.
- A
- 24
Which type of join returns all records from the left table and matching records from the right table, with NULLs where there is no match?
- A
CROSS JOIN
- B
RIGHT JOIN
- C
LEFT JOIN
- D
INNER JOIN
Correct answer
CLEFT JOIN
Explanation
A LEFT JOIN (or LEFT OUTER JOIN) returns all rows from the left table. If there is no match in the right table, NULLs are used for right table columns.
- A
- 25
What is a self join?
- A
Joining two tables that have the same structure
- B
Joining a table with its primary key
- C
Joining a table with a view of itself
- D
Joining a table with itself using different aliases
Correct answer
DJoining a table with itself using different aliases
Explanation
A self join is when a table is joined to itself. This is done by using different aliases for the same table, e.g., to find employee-manager relationships.
- A
- 26
What is a composite primary key?
- A
A primary key that can have duplicate values
- B
A primary key that is automatically generated
- C
A primary key that consists of multiple columns
- D
A primary key that is a foreign key in another table
Correct answer
CA primary key that consists of multiple columns
Explanation
A composite primary key is a primary key made up of two or more columns. For example, in order_items, the combination of order_id and product_id uniquely identifies each row.
- A
- 27
What does the UNION operator do?
- A
It combines rows from two or more queries into a single result set
- B
It joins tables based on a common column
- C
It combines columns from two tables
- D
It returns the intersection of two queries
Correct answer
AIt combines rows from two or more queries into a single result set
Explanation
UNION combines the results of multiple SELECT statements into one result set. Each SELECT must have the same number of columns.
- A
- 28
In MySQL Workbench, what does the 'safe update mode' prevent?
- A
Inserting duplicate rows into a table
- B
Executing DDL statements that modify table structure
- C
Updating or deleting multiple rows without a key in the WHERE clause
- D
Running SELECT queries without a WHERE clause
Correct answer
CUpdating or deleting multiple rows without a key in the WHERE clause
Explanation
Safe update mode prevents accidental updates or deletes of many rows. It requires a key (e.g., primary key) in the WHERE clause for UPDATE/DELETE on multiple rows.
- A
- 29
How do you insert a new row into a table while letting MySQL auto-generate the primary key value?
- A
Omit the primary key column from the INSERT statement
- B
Use DEFAULT for the primary key column
- C
All of the above
- D
Use NULL for the primary key column
Correct answer
CAll of the above
Explanation
You can omit the primary key column (if auto_increment), or explicitly use NULL or DEFAULT. MySQL will generate the next value.
- A
- 30
What function returns the ID generated by an INSERT operation?
- A
GET_LAST_ID()
- B
LAST_INSERT_ID()
- C
CURRENT_INSERT_ID()
- D
IDENTITY()
Correct answer
BLAST_INSERT_ID()
Explanation
LAST_INSERT_ID() is a MySQL function that returns the auto_increment value generated by the most recent INSERT statement.
- A
- 31
Which statement is used to create a new table by copying the result of a query?
- A
INSERT INTO ... SELECT ...
- B
CREATE TABLE ... AS SELECT ...
- C
SELECT ... INTO TABLE ...
- D
CREATE TABLE ... FROM SELECT ...
Correct answer
BCREATE TABLE ... AS SELECT ...
Explanation
In MySQL, 'CREATE TABLE new_table AS SELECT ...' creates a new table and inserts the query results. Note that primary key and auto_increment attributes are not copied.
- A
- 32
What does the UPDATE statement do if no WHERE clause is specified?
- A
It updates only the first row in the table
- B
It updates all rows in the table
- C
It prompts the user to confirm
- D
It does nothing and returns an error
Correct answer
BIt updates all rows in the table
Explanation
Without a WHERE clause, the UPDATE statement modifies every row in the table. This is powerful and dangerous, so caution is needed.
- A
- 33
In an UPDATE statement, how can you set a column to its default value?
- A
SET column = DEFAULT
- B
SET column = ''
- C
SET column = 0
- D
SET column = NULL
Correct answer
ASET column = DEFAULT
Explanation
Using the DEFAULT keyword sets the column to its defined default value. For example, if a column has a default of 0, 'SET points = DEFAULT' sets it to 0.
- A
- 34
What is a subquery?
- A
A SELECT statement nested inside another SQL statement
- B
A query that uses the UNION operator
- C
A query that joins more than two tables
- D
A query that returns multiple rows
Correct answer
AA SELECT statement nested inside another SQL statement
Explanation
A subquery is a SELECT statement that is used within another SQL statement (e.g., in WHERE, FROM, or SET clauses). It is enclosed in parentheses.
- A
- 35
When using a subquery in a WHERE clause with an equality operator, what must the subquery return?
- A
A single value
- B
A single row with multiple columns
- C
A list of values
- D
Any number of rows
Correct answer
AA single value
Explanation
If using '=' with a subquery, the subquery must return exactly one value. For multiple values, use IN or other operators.
- A
- 36
Which modifier in MySQL Workbench's 'safe update mode' can be turned off to allow updating multiple rows?
- A
All of the above
- B
Disable 'Safe Updates' in the Connection settings
- C
Uncheck 'Save updates' in SQL Editor preferences
- D
Use the '--safe-updates=0' command
Correct answer
CUncheck 'Save updates' in SQL Editor preferences
Explanation
In MySQL Workbench, you can disable safe updates by going to Preferences > SQL Editor and unchecking 'Safe Updates' (Save updates).
- A
- 37
How do you delete all rows from a table?
- A
DROP TABLE table_name;
- B
DELETE * FROM table_name;
- C
DELETE FROM table_name;
- D
TRUNCATE table_name;
Correct answer
CDELETE FROM table_name;
Explanation
DELETE FROM table_name without a WHERE clause deletes all rows. TRUNCATE also removes all rows but is faster and cannot be rolled back in some cases.
- A

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