SQL Course Introduction
- 65Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is a database?
65 questions
- 1
What is a database?
Model answer
A database is a collection of data stored in a format that can be easily accessed.
Explanation
The definition is given at the start of the course.
- 2
What is a DBMS?
Model answer
A DBMS (Database Management System) is software used to manage databases by executing instructions for querying or modifying data.
Explanation
The course defines DBMS as the software that connects to and manages databases.
- 3
What are the two main categories of database management systems?
Model answer
Relational and non-relational (NoSQL).
Explanation
The course categorizes DBMS into relational and non-relational.
- 4
In relational databases, how is data organized?
Model answer
Data is stored in tables that are linked to each other using relationships.
Explanation
Relational databases use tables and relationships.
- 5
What is SQL?
Model answer
SQL (Structured Query Language) is the language used to work with relational database management systems.
Explanation
SQL is used to query or modify data in RDBMS.
- 6
Name three popular relational database management systems mentioned in the course.
Model answer
MySQL, SQL Server, and Oracle.
Explanation
These are listed as popular RDBMS.
- 7
Are SQL implementations identical across different database systems?
Model answer
No, each DBMS has a different flavor of SQL, but they are very similar and based on the standard SQL specification.
Explanation
The course states that implementations vary but follow the standard.
- 8
What is the historical origin of the name SQL?
Model answer
SQL was originally called SQUEL (Structured English Query Language) at IBM, but the acronym was changed to SQL because SQUEL was a trademark.
Explanation
The pronunciation debate is explained with this history.
- 9
What is the default MySQL port number?
Model answer
Explanation
During installation, the default port is mentioned as 3306.
- 10
What is MySQL Workbench used for?
Model answer
MySQL Workbench is a graphical tool to connect to the MySQL server and manage databases.
Explanation
It is described as the graphical tool for managing databases.
- 11
In MySQL Workbench, what does the 'Schemas' tab display?
Model answer
It shows the databases in the current database server.
Explanation
The navigator panel has a Schemas tab for viewing databases.
- 12
How do you select a database for querying in MySQL Workbench?
Model answer
Use the USE statement followed by the database name, or double-click the database in the Schemas tab.
Explanation
The course shows both methods.
- 13
Write the simplest SQL query to retrieve all columns and all rows from the customers table.
Model answer
SELECT * FROM customers;
Explanation
This is the basic SELECT * FROM syntax.
- 14
What does the asterisk (*) do in a SELECT statement?
Model answer
It returns all columns from the table.
Explanation
The asterisk is a shortcut for all columns.
- 15
How do you specify the columns you want to retrieve in a SELECT query?
Model answer
List the column names separated by commas after SELECT.
Explanation
Instead of *, you can list specific columns.
- 16
What is the purpose of the FROM clause?
Model answer
It specifies the table from which to retrieve data.
Explanation
FROM is required to indicate the source table.
- 17
What does the WHERE clause do?
Model answer
It filters rows based on a condition.
Explanation
WHERE is used to select only rows that satisfy the condition.
- 18
What does the ORDER BY clause do?
Model answer
It sorts the result set by one or more columns.
Explanation
ORDER BY can be ascending (default) or descending.
- 19
What is the correct order of clauses in a SELECT statement?
Model answer
SELECT, FROM, WHERE, ORDER BY.
Explanation
The order is fixed; changing it causes a syntax error.
- 20
How do you use an alias for a column in a SELECT query?
Model answer
Use the AS keyword after the column or expression, e.g., points AS discount.
Explanation
Aliases provide descriptive column names.
- 21
How do you remove duplicate rows from a query result?
Model answer
Use the DISTINCT keyword.
Explanation
SELECT DISTINCT returns unique values.
- 22
What operator is used for equality comparison in SQL?
Model answer
= (single equal sign).
Explanation
The equality operator is =, not ==.
- 23
What are the two ways to write the 'not equal' operator in SQL?
Model answer
!= and <>.
Explanation
Both are valid for not equal.
- 24
How do you represent string values in SQL?
Model answer
Enclosed in single quotes (or double quotes).
Explanation
Strings must be quoted; single quotes are conventional.
- 25
How do you represent date values in MySQL?
Model answer
Using the format 'YYYY-MM-DD' inside quotes.
Explanation
Dates are strings in this format.
- 26
What does the AND logical operator do?
Model answer
It returns rows that satisfy both conditions.
Explanation
Both conditions must be true.
- 27
What does the OR logical operator do?
Model answer
It returns rows that satisfy at least one condition.
Explanation
At least one condition must be true.
- 28
Which logical operator has higher precedence: AND or OR?
Model answer
AND has higher precedence than OR.
Explanation
AND is evaluated first unless parentheses are used.
- 29
How do you negate a condition in SQL?
Model answer
Use the NOT operator.
Explanation
NOT reverses a boolean condition.
- 30
What is the IN operator used for?
Model answer
To compare a column to a list of values.
Explanation
IN is shorthand for multiple OR conditions.
- 31
What does the BETWEEN operator do?
Model answer
It checks if a value is within a range (inclusive).
Explanation
BETWEEN is inclusive of both endpoints.
- 32
In the LIKE operator, what does the percent sign (%) represent?
Model answer
Any number of characters (including zero).
Explanation
% is a wildcard for multiple characters.
- 33
In the LIKE operator, what does the underscore (_) represent?
Model answer
A single character.
Explanation
_ matches exactly one character.
- 34
What does the caret (^) mean in a MySQL regular expression?
Model answer
It represents the beginning of a string.
Explanation
^ anchors the pattern to the start.
- 35
What does the dollar sign ($) mean in a MySQL regular expression?
Model answer
It represents the end of a string.
Explanation
$ anchors the pattern to the end.
- 36
In a regular expression, how do you specify multiple alternative patterns?
Model answer
Use the vertical bar (|) as a logical OR.
Explanation
| separates patterns.
- 37
What do square brackets [] do in a regular expression?
Model answer
They match any single character listed inside.
Explanation
[abc] matches a, b, or c.
- 38
How do you check for NULL values in SQL?
Model answer
Use the IS NULL operator.
Explanation
NULL cannot be compared with =; use IS NULL.
- 39
What is the default sort order in ORDER BY?
Model answer
Ascending (ASC).
Explanation
If not specified, ASC is used.
- 40
How do you sort results in descending order?
Model answer
Add the DESC keyword after the column in ORDER BY.
Explanation
DESC reverses the sort order.
- 41
Can you sort by a column alias in MySQL?
Model answer
Yes, you can use the alias in the ORDER BY clause.
Explanation
MySQL allows ordering by an alias defined in SELECT.
- 42
What does the LIMIT clause do?
Model answer
It limits the number of rows returned.
Explanation
LIMIT restricts the result set size.
- 43
How do you paginate results with LIMIT?
Model answer
Use LIMIT with an offset: LIMIT offset, row_count.
Explanation
The offset skips rows before taking the row_count.
- 44
What is an inner join?
Model answer
An inner join returns only rows that have matching values in both tables.
Explanation
It is the default type of join.
- 45
How do you write an inner join between two tables?
Model answer
SELECT * FROM table1 JOIN table2 ON condition;
Explanation
The JOIN keyword with an ON clause.
- 46
What is a self-join?
Model answer
A self-join is when a table is joined with itself.
Explanation
It requires different aliases for the same table.
- 47
How do you join tables from different databases?
Model answer
Prefix the table name with the database name: database.table.
Explanation
This is necessary if the table is not in the current database.
- 48
What is a left outer join?
Model answer
It returns all rows from the left table and matching rows from the right table; non-matching rows from the right have NULLs.
Explanation
LEFT JOIN preserves all left table rows.
- 49
What is a right outer join?
Model answer
It returns all rows from the right table and matching rows from the left table; non-matching rows from the left have NULLs.
Explanation
RIGHT JOIN is less common; LEFT JOIN is preferred.
- 50
What is a cross join?
Model answer
It returns the Cartesian product of two tables, combining each row from the first table with every row from the second.
Explanation
No join condition is specified.
- 51
When can you use the USING clause instead of ON?
Model answer
When the join columns have exactly the same name in both tables.
Explanation
USING simplifies the join condition.
- 52
What is a natural join?
Model answer
It joins tables automatically based on columns with the same name.
Explanation
Natural joins are discouraged because they can produce unexpected results.
- 53
What is a composite primary key?
Model answer
A primary key that consists of more than one column.
Explanation
The order_items table has a composite primary key (order_id, product_id).
- 54
How do you write a compound join condition?
Model answer
Use AND to combine multiple conditions in the ON clause.
Explanation
For composite primary keys, all key columns must match.
- 55
What is the implicit join syntax?
Model answer
It lists multiple tables in the FROM clause separated by commas and places the join condition in the WHERE clause.
Explanation
This older syntax is discouraged because forgetting the WHERE clause produces a cross join.
- 56
What does the UNION operator do?
Model answer
It combines the result sets of two or more queries into a single result set.
Explanation
The number of columns must be the same in all queries.
- 57
What function returns the auto-generated ID after an INSERT?
Model answer
LAST_INSERT_ID().
Explanation
This function returns the last generated ID in the current session.
- 58
What does the INSERT INTO statement do?
Model answer
It inserts one or more rows into a table.
Explanation
You can specify columns and values.
- 59
How do you insert multiple rows in a single INSERT statement?
Model answer
Separate each row's values with commas inside the VALUES clause.
Explanation
Example: INSERT INTO table VALUES (row1), (row2), ...
- 60
How do you create a copy of a table using a query?
Model answer
Use CREATE TABLE new_table AS SELECT * FROM existing_table;
Explanation
This creates a new table with the same data but without primary keys or auto-increment.
- 61
What is a subquery?
Model answer
A SELECT statement that is nested inside another SQL statement.
Explanation
Subqueries can be used in SELECT, INSERT, UPDATE, DELETE.
- 62
How do you update a row in SQL?
Model answer
Use UPDATE table_name SET column = value WHERE condition;
Explanation
The WHERE clause specifies which rows to update.
- 63
How do you delete rows in SQL?
Model answer
Use DELETE FROM table_name WHERE condition;
Explanation
If no WHERE clause, all rows are deleted.
- 64
What does 'safe update mode' in MySQL Workbench prevent?
Model answer
It prevents executing UPDATE or DELETE statements that affect multiple rows without a key condition.
Explanation
Safe update mode can be disabled in preferences.
- 65
How do you restore the databases to their original state after modifications?
Model answer
Execute the create_databases.sql script again.
Explanation
This recreates all databases from scratch.

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