Exit Chapter 05 · 🖥️ MySQL SQL Revision Tour — Quiz

Playing as a guest? to earn XP and track your progress.

Question 1 of 60 0 correct so far

🖥️ MySQL SQL Revision Tour Quiz

Q1.

In the Relational Model, what is another name for a 'Table'?

Explanation

In relational database terminology, a Table is referred to as a Relation.

Q2.

What does a 'Tuple' represent in a relational table?

Explanation

A Tuple represents a single row or record within a relation.

Q3.

What is the term used for a 'Column' in a relational table?

Explanation

An Attribute refers to a column or field in a table.

Q4.

What is the 'Degree' of a relation?

Explanation

The Degree of a relation is the total number of attributes (columns) it contains.

Q5.

What is the 'Cardinality' of a relation?

Explanation

Cardinality refers to the total number of tuples (rows) in a relation.

Q6.

Which key uniquely identifies each record in a table and cannot be NULL?

Explanation

The Primary Key uniquely identifies each row and must contain a non-NULL value.

Q7.

If a table has 5 rows and 3 columns, what is its Cardinality?

Explanation

Cardinality is the number of rows, which is 5.

Q8.

A table has columns: ID, Name, Age. What is its Degree?

Explanation

Degree is the number of columns. Here there are 3 columns.

Q9.

What do we call a Candidate Key that is NOT selected as the Primary Key?

Explanation

An Alternate Key is a Candidate Key that was not chosen to be the Primary Key.

Q10.

Which key is used to establish a relationship between two tables?

Explanation

A Foreign Key links a column in one table to the Primary Key of another table.

Q11.

Which of the following is a DDL command?

Explanation

CREATE is a Data Definition Language (DDL) command used to define structure.

Q12.

Which of the following is a DML command?

Explanation

INSERT is a Data Manipulation Language (DML) command used to add data.

Q13.

What is the standard format for DATE in MySQL?

Explanation

MySQL stores dates in the 'YYYY-MM-DD' format.

Q14.

Which data type would you use for a fixed-length string?

Explanation

CHAR is used for fixed-length strings, padding with spaces if the text is shorter.

Q15.

Which data type is more memory efficient for storing variable-length names?

Explanation

VARCHAR allocates memory based on the actual length of the string, making it efficient for variable-length data.

Q16.

Which command is used to select a database to work with?

Explanation

The USE <database_name> command is used to select the current database.

Q17.

What is the correct syntax to create a table?

Explanation

The correct syntax is CREATE TABLE table_name (columns...);.

Q18.

Which keyword is used to see the structure of an existing table?

Explanation

DESC or DESCRIBE is used to view the structure of a table.

Q19.

How do you insert a new record into a table?

Explanation

The INSERT INTO command is used to add new rows to a table.

Q20.

Which query selects all columns from a table named 'Student'?

Explanation

The asterisk * is a wildcard character that selects all columns.

Q21.

What is the purpose of the DISTINCT keyword?

Explanation

DISTINCT eliminates duplicate rows from the query result (output), but does not delete them from the table.

Q22.

Which clause is used to filter records based on a condition?

Explanation

The WHERE clause is used to filter records that meet a specified condition.

Q23.

How do you define a column alias in SQL?

Explanation

The AS keyword is used to assign an alias (temporary name) to a column.

Q24.

What is the result of SELECT 100 + NULL;?

Explanation

Any arithmetic operation performed with NULL results in NULL.

Q25.

Which operator checks if a value falls within a range?

Explanation

The BETWEEN operator selects values within a given range (inclusive).

Q26.

The query SELECT * FROM Student WHERE Marks BETWEEN 80 AND 90 will include:

Explanation

The BETWEEN operator is inclusive of both the start and end values.

Q27.

Which operator is used to match a value against a list of values?

Explanation

The IN operator allows you to specify multiple values in a WHERE clause.

Q28.

Which wildcard character represents zero, one, or multiple characters?

Explanation

The % (percent) wildcard represents zero or more characters.

Q29.

Which wildcard character represents exactly one character?

Explanation

The _ (underscore) wildcard represents exactly one single character.

Q30.

To find names starting with 'A', which pattern is used?

Explanation

'A%' matches any string starting with 'A' followed by any number of characters.

Q31.

What is the correct syntax to check for a NULL value?

Explanation

You must use IS NULL to check for NULL values; = does not work.

Q32.

What is the correct syntax to check for a non-NULL value?

Explanation

The correct operator is IS NOT NULL.

Q33.

Which constraint ensures that a column cannot have empty values?

Explanation

NOT NULL constraint enforces a column to NOT accept NULL values.

Q34.

Which constraint ensures all values in a column are different?

Explanation

The UNIQUE constraint ensures that all values in a column are distinct.

Q35.

Which constraint provides a default value if none is specified?

Explanation

The DEFAULT constraint inserts a specified value when no value is provided during insertion.

Q36.

Which constraint is used to validate data against a specific condition?

Explanation

The CHECK constraint is used to limit the value range that can be placed in a column.

Q37.

A Primary Key constraint is a combination of which two constraints?

Explanation

A Primary Key must be both UNIQUE (no duplicates) and NOT NULL (no empty values).

Q38.

Which command is used to modify data in an existing row?

Explanation

UPDATE is the DML command used to modify existing records.

Q39.

If you omit the WHERE clause in an UPDATE statement, what happens?

Explanation

Without a WHERE clause, the UPDATE statement applies the change to every row in the table.

Q40.

Which command is used to remove rows from a table?

Explanation

DELETE is used to remove rows. DROP removes the entire table.

Q41.

If you omit the WHERE clause in a DELETE statement, what happens?

Explanation

Without a WHERE clause, DELETE removes all data from the table but keeps the structure.

Q42.

Which command is used to add a new column to an existing table?

Explanation

ALTER TABLE is used to modify the structure, such as adding a column.

Q43.

Which keyword is used with ALTER TABLE to change a column's datatype?

Explanation

The MODIFY clause is used with ALTER TABLE to change a column definition.

Q44.

Which command removes a table and its data permanently?

Explanation

DROP TABLE removes the table definition and all its data permanently.

Q45.

Which operator has the highest precedence?

Explanation

Logical operator precedence is NOT > AND > OR.

Q46.

What will SELECT 5*2; return?

Explanation

SELECT can be used as a simple calculator. 5 * 2 = 10.

Q47.

How can you copy data from one table to another?

Explanation

The syntax INSERT INTO <table> SELECT ... allows copying data from one table to another.

Q48.

Is MySQL case-sensitive for keywords like SELECT and FROM?

Explanation

SQL keywords are not case-sensitive. SELECT and select are the same.

Q49.

Which query matches names having exactly 4 characters?

Explanation

Four underscores ____ match exactly four characters.

Q50.

In the query SELECT Name, Salary + 100 FROM Emp, what does the + 100 do?

Explanation

It performs a calculation for display purposes only; the underlying data is not changed.

Q51.

Can a table have multiple Primary Keys?

Explanation

A table can have only ONE Primary Key definition, but that key can consist of multiple columns (Composite Key).

Q52.

Which command allows you to delete a specific column from a table?

Explanation

You use ALTER TABLE <table_name> DROP COLUMN <col_name>.

Q53.

What is the error in SELECT * FROM Student WHERE Name = NULL?

Explanation

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).

Q54.

Which of these is NOT a valid constraint?

Explanation

Secondary Key is a concept (often an alternate key used for indexing), but not a standard SQL constraint keyword like the others.

Q55.

The Cartesian Product of two tables with 2 and 3 rows respectively will have how many rows?

Explanation

Cartesian Product rows = Rows(A) * Rows(B) = 2 * 3 = 6.

Q56.

Which type of quote is used for string values in SQL?

Explanation

String literals are enclosed in single quotes (e.g., 'Text').

Q57.

What does the logic OR do in a WHERE clause?

Explanation

OR returns true if either one of the conditions is true.

Q58.

Can a Primary Key column accept duplicate values?

Explanation

No, a Primary Key must be unique.

Q59.

If you want to create a table with a column Age that must be above 18, which constraint do you use?

Explanation

The CHECK constraint allows you to specify a condition (e.g., CHECK (Age > 18)).

Q60.

Which command is used to permanently save changes? (Bonus: usually next chapter but relevant concept)

Explanation

COMMIT is used to save transaction changes permanently.