SQL MCQ Quiz - Objective Question with Answer for SQL - Download Free PDF
Last updated on Apr 19, 2025
Latest SQL MCQ Objective Questions
SQL Question 1:
The SQL keyword _______ is used with wildcards.
Answer (Detailed Solution Below)
SQL Question 1 Detailed Solution
The correct answer is LIKE.
Key Points
- The LIKE keyword is used in SQL to search for a specified pattern in a column.
- It is often used with wildcards to perform pattern matching within a query.
- There are two main wildcards used in conjunction with LIKE:
- The percentage sign (%) represents zero, one, or multiple characters.
- The underscore (_) represents a single character.
- For example:
SELECT * FROM Customers WHERE City LIKE 'New%';
- This query finds any values that start with "New".SELECT * FROM Customers WHERE City LIKE '_ew%';
- This query finds any values where the second and third characters are "ew".
Additional Information
- The LIKE keyword is case-insensitive in some database systems, but case-sensitive in others.
- Using wildcards can impact the performance of SQL queries, especially with large datasets.
- The LIKE keyword is primarily used in SELECT, UPDATE, and DELETE statements.
- Other SQL keywords related to pattern matching include SIMILAR TO and REGEXP (regular expressions).
SQL Question 2:
Which of the following is correct syntax for inserting foreign key constraint in a relation?
Answer (Detailed Solution Below)
SQL Question 2 Detailed Solution
The correct answer is ALTER TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name).
Key Points
- To add a foreign key constraint, the ALTER TABLE statement is used to modify the existing table structure.
- The syntax for adding a foreign key is:
ALTER TABLE table_name ADD FOREIGN KEY (attribute_name) REFERENCES referenced_table_name(attribute_name);
- This statement ensures referential integrity by creating a link between the foreign key in one table and the primary key in another table.
- It is important to specify the table and attribute names correctly for both the foreign key and the referenced primary key.
Additional Information
- Foreign keys help maintain data consistency and integrity across related tables.
- They prevent actions that would destroy the relationships between tables, such as deleting a record that is referenced by a foreign key in another table.
- Foreign key constraints can also enforce cascading actions such as ON DELETE CASCADE or ON UPDATE CASCADE, which automatically update or delete dependent records.
- Properly defining foreign keys is crucial in database design to ensure data is stored in a normalized and efficient manner.
SQL Question 3:
Using which SQL Comparison Operator can we find the data that matches our query?
Answer (Detailed Solution Below)
SQL Question 3 Detailed Solution
Top SQL MCQ Objective Questions
SQL Question 4:
Using which SQL Comparison Operator can we find the data that matches our query?
Answer (Detailed Solution Below)
SQL Question 4 Detailed Solution
SQL Question 5:
The SQL keyword _______ is used with wildcards.
Answer (Detailed Solution Below)
SQL Question 5 Detailed Solution
The correct answer is LIKE.
Key Points
- The LIKE keyword is used in SQL to search for a specified pattern in a column.
- It is often used with wildcards to perform pattern matching within a query.
- There are two main wildcards used in conjunction with LIKE:
- The percentage sign (%) represents zero, one, or multiple characters.
- The underscore (_) represents a single character.
- For example:
SELECT * FROM Customers WHERE City LIKE 'New%';
- This query finds any values that start with "New".SELECT * FROM Customers WHERE City LIKE '_ew%';
- This query finds any values where the second and third characters are "ew".
Additional Information
- The LIKE keyword is case-insensitive in some database systems, but case-sensitive in others.
- Using wildcards can impact the performance of SQL queries, especially with large datasets.
- The LIKE keyword is primarily used in SELECT, UPDATE, and DELETE statements.
- Other SQL keywords related to pattern matching include SIMILAR TO and REGEXP (regular expressions).
SQL Question 6:
Which of the following is correct syntax for inserting foreign key constraint in a relation?
Answer (Detailed Solution Below)
SQL Question 6 Detailed Solution
The correct answer is ALTER TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name).
Key Points
- To add a foreign key constraint, the ALTER TABLE statement is used to modify the existing table structure.
- The syntax for adding a foreign key is:
ALTER TABLE table_name ADD FOREIGN KEY (attribute_name) REFERENCES referenced_table_name(attribute_name);
- This statement ensures referential integrity by creating a link between the foreign key in one table and the primary key in another table.
- It is important to specify the table and attribute names correctly for both the foreign key and the referenced primary key.
Additional Information
- Foreign keys help maintain data consistency and integrity across related tables.
- They prevent actions that would destroy the relationships between tables, such as deleting a record that is referenced by a foreign key in another table.
- Foreign key constraints can also enforce cascading actions such as ON DELETE CASCADE or ON UPDATE CASCADE, which automatically update or delete dependent records.
- Properly defining foreign keys is crucial in database design to ensure data is stored in a normalized and efficient manner.