Playing as a guest? to earn XP and track your progress.
🖥️ MySQL SQL Revision Tour Quiz
🖥️ MySQL SQL Revision Tour
In the Relational Model, what is another name for a 'Table'?
Tuple
Attribute
Relation
Degree
In relational database terminology, a Table is referred to as a Relation.
What does a 'Tuple' represent in a relational table?
A column
A row
A key
The table name
A Tuple represents a single row or record within a relation.
What is the term used for a 'Column' in a relational table?
Degree
Tuple
Cardinality
Attribute
An Attribute refers to a column or field in a table.
What is the 'Degree' of a relation?
Total number of rows
Total number of columns
Total number of constraints
Total number of null values
The Degree of a relation is the total number of attributes (columns) it contains.
What is the 'Cardinality' of a relation?
Total number of rows
Total number of columns
The size of the file
Number of primary keys
Cardinality refers to the total number of tuples (rows) in a relation.
Which key uniquely identifies each record in a table and cannot be NULL?
Foreign Key
Alternate Key
Candidate Key
Primary Key
The Primary Key uniquely identifies each row and must contain a non-NULL value.
If a table has 5 rows and 3 columns, what is its Cardinality?
3
5
8
15
Cardinality is the number of rows, which is 5.
A table has columns: ID, Name, Age. What is its Degree?
1
2
3
Unknown
Degree is the number of columns. Here there are 3 columns.
What do we call a Candidate Key that is NOT selected as the Primary Key?
Foreign Key
Super Key
Alternate Key
Unique Key
An Alternate Key is a Candidate Key that was not chosen to be the Primary Key.
Which key is used to establish a relationship between two tables?
Primary Key
Foreign Key
Alternate Key
Candidate Key
A Foreign Key links a column in one table to the Primary Key of another table.
Which of the following is a DDL command?
SELECT
INSERT
UPDATE
CREATE
CREATE is a Data Definition Language (DDL) command used to define structure.
Which of the following is a DML command?
ALTER
DROP
INSERT
DESCRIBE
INSERT is a Data Manipulation Language (DML) command used to add data.
What is the standard format for DATE in MySQL?
DD-MM-YYYY
YYYY-MM-DD
MM-DD-YYYY
YY-MM-DD
MySQL stores dates in the 'YYYY-MM-DD' format.
Which data type would you use for a fixed-length string?
VARCHAR
TEXT
CHAR
STRING
CHAR is used for fixed-length strings, padding with spaces if the text is shorter.
Which data type is more memory efficient for storing variable-length names?
CHAR
VARCHAR
INT
FLOAT
VARCHAR allocates memory based on the actual length of the string, making it efficient for variable-length data.
Which command is used to select a database to work with?
SELECT DATABASE
OPEN
USE
START
The USE <database_name> command is used to select the current database.
What is the correct syntax to create a table?
MAKE TABLE table_name...
CREATE TABLE table_name...
NEW TABLE table_name...
ADD TABLE table_name...
The correct syntax is CREATE TABLE table_name (columns...);.
Which keyword is used to see the structure of an existing table?
SHOW
DESC
STRUCTURE
VIEW
DESC or DESCRIBE is used to view the structure of a table.
How do you insert a new record into a table?
ADD INTO
INSERT INTO
PUT INTO
UPDATE INTO
The INSERT INTO command is used to add new rows to a table.
Which query selects all columns from a table named 'Student'?
SELECT ALL Student
SELECT * FROM Student
SELECT Student
SHOW Student
The asterisk * is a wildcard character that selects all columns.
What is the purpose of the DISTINCT keyword?
To sort data
To delete duplicates from the table
To show only unique values in the output
To format data
DISTINCT eliminates duplicate rows from the query result (output), but does not delete them from the table.
Which clause is used to filter records based on a condition?
HAVING
WHERE
FILTER
IF
The WHERE clause is used to filter records that meet a specified condition.
How do you define a column alias in SQL?
RENAME
ALIAS
AS
IS
The AS keyword is used to assign an alias (temporary name) to a column.
What is the result of SELECT 100 + NULL;?
100
0
NULL
Error
Any arithmetic operation performed with NULL results in NULL.
Which operator checks if a value falls within a range?
IN
BETWEEN
LIKE
RANGE
The BETWEEN operator selects values within a given range (inclusive).
The query SELECT * FROM Student WHERE Marks BETWEEN 80 AND 90 will include:
Only 80
Only 90
Neither 80 nor 90
Both 80 and 90
The BETWEEN operator is inclusive of both the start and end values.
Which operator is used to match a value against a list of values?
BETWEEN
LIKE
IN
MATCH
The IN operator allows you to specify multiple values in a WHERE clause.
Which wildcard character represents zero, one, or multiple characters?
_
?
%
*
The % (percent) wildcard represents zero or more characters.
Which wildcard character represents exactly one character?
_
%
?
#
The _ (underscore) wildcard represents exactly one single character.
To find names starting with 'A', which pattern is used?
'A_'
'%A'
'A%'
'_A'
'A%' matches any string starting with 'A' followed by any number of characters.
What is the correct syntax to check for a NULL value?
WHERE col = NULL
WHERE col IS NULL
WHERE col == NULL
WHERE col EQUALS NULL
You must use IS NULL to check for NULL values; = does not work.
What is the correct syntax to check for a non-NULL value?
WHERE col != NULL
WHERE col <> NULL
WHERE col NOT NULL
WHERE col IS NOT NULL
The correct operator is IS NOT NULL.
Which constraint ensures that a column cannot have empty values?
UNIQUE
NOT NULL
DEFAULT
CHECK
NOT NULL constraint enforces a column to NOT accept NULL values.
Which constraint ensures all values in a column are different?
NOT NULL
CHECK
UNIQUE
DEFAULT
The UNIQUE constraint ensures that all values in a column are distinct.
Which constraint provides a default value if none is specified?
CHECK
UNIQUE
DEFAULT
PRIMARY
The DEFAULT constraint inserts a specified value when no value is provided during insertion.
Which constraint is used to validate data against a specific condition?
VALIDATE
CHECK
TEST
RULE
The CHECK constraint is used to limit the value range that can be placed in a column.
A Primary Key constraint is a combination of which two constraints?
UNIQUE + DEFAULT
NOT NULL + CHECK
UNIQUE + NOT NULL
DEFAULT + CHECK
A Primary Key must be both UNIQUE (no duplicates) and NOT NULL (no empty values).
Which command is used to modify data in an existing row?
ALTER
MODIFY
CHANGE
UPDATE
UPDATE is the DML command used to modify existing records.
If you omit the WHERE clause in an UPDATE statement, what happens?
It updates the first row only
It throws an error
It updates all rows
It updates nothing
Without a WHERE clause, the UPDATE statement applies the change to every row in the table.
Which command is used to remove rows from a table?
REMOVE
DROP
DELETE
CUT
DELETE is used to remove rows. DROP removes the entire table.
If you omit the WHERE clause in a DELETE statement, what happens?
It deletes the table structure
It deletes all rows
It deletes the last row
It does nothing
Without a WHERE clause, DELETE removes all data from the table but keeps the structure.
Which command is used to add a new column to an existing table?
UPDATE TABLE
ALTER TABLE
MODIFY TABLE
ADD COLUMN
ALTER TABLE is used to modify the structure, such as adding a column.
Which keyword is used with ALTER TABLE to change a column's datatype?
CHANGE
MODIFY
UPDATE
SET
The MODIFY clause is used with ALTER TABLE to change a column definition.
Which command removes a table and its data permanently?
DELETE TABLE
ERASE TABLE
DROP TABLE
REMOVE TABLE
DROP TABLE removes the table definition and all its data permanently.
Which operator has the highest precedence?
OR
AND
NOT
Between
Logical operator precedence is NOT > AND > OR.
What will SELECT 5*2; return?
52
10
7
Error
SELECT can be used as a simple calculator. 5 * 2 = 10.
How can you copy data from one table to another?
COPY TABLE
INSERT INTO ... SELECT
SELECT INTO
DUPLICATE
The syntax INSERT INTO <table> SELECT ... allows copying data from one table to another.
Is MySQL case-sensitive for keywords like SELECT and FROM?
Yes
No
Only on Linux
Only on Windows
SQL keywords are not case-sensitive. SELECT and select are the same.
Which query matches names having exactly 4 characters?
LIKE '____'
LIKE '%4'
LIKE '....'
LIKE '4'
Four underscores ____ match exactly four characters.
In the query SELECT Name, Salary + 100 FROM Emp, what does the + 100 do?
Updates the table permanently
Displays the salary increased by 100
Adds a new column
It is an error
It performs a calculation for display purposes only; the underlying data is not changed.
Can a table have multiple Primary Keys?
Yes
No, but it can have a Composite Primary Key
Yes, up to 3
Yes, if they are integers
A table can have only ONE Primary Key definition, but that key can consist of multiple columns (Composite Key).
Which command allows you to delete a specific column from a table?
DELETE COLUMN
DROP COLUMN
ALTER TABLE ... DROP
REMOVE COLUMN
You use ALTER TABLE <table_name> DROP COLUMN <col_name>.
What is the error in SELECT * FROM Student WHERE Name = NULL?
Syntax error
It will always return 0 rows
Name cannot be NULL
No error
While it might not be a syntax crash, logically it is an error because NULL = NULL is never true. It returns 0 rows. (IS NULL should be used).
Which of these is NOT a valid constraint?
PRIMARY KEY
FOREIGN KEY
SECONDARY KEY
UNIQUE
Secondary Key is a concept (often an alternate key used for indexing), but not a standard SQL constraint keyword like the others.
The Cartesian Product of two tables with 2 and 3 rows respectively will have how many rows?
5
6
2
3
Cartesian Product rows = Rows(A) * Rows(B) = 2 * 3 = 6.
Which type of quote is used for string values in SQL?
Single quotes
Backticks
Parentheses
Brackets
String literals are enclosed in single quotes (e.g., 'Text').
What does the logic OR do in a WHERE clause?
Both conditions must be true
At least one condition must be true
Neither condition is true
Inverts the condition
OR returns true if either one of the conditions is true.
Can a Primary Key column accept duplicate values?
Yes
No
Only if NULL
Only once
No, a Primary Key must be unique.
If you want to create a table with a column Age that must be above 18, which constraint do you use?
UNIQUE
DEFAULT
CHECK
INDEX
The CHECK constraint allows you to specify a condition (e.g., CHECK (Age > 18)).
Which command is used to permanently save changes? (Bonus: usually next chapter but relevant concept)
SAVE
COMMIT
ROLLBACK
Keep
COMMIT is used to save transaction changes permanently.