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.

  1. LIKE
  2. IN
  3. NOT IN
  4. DISTINCT

Answer (Detailed Solution Below)

Option 1 : LIKE

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?

  1. ALTER TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)
  2. ADD TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)
  3. ALTER TABLE table_name REFERENCES referenced_table_ name(attribute name) ADD FOREIGN KEY (attribute name)
  4. MODIFY TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)

Answer (Detailed Solution Below)

Option 1 : ALTER TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)

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?

  1. SQL Not Equal Operator (!=)
  2. SQL Equal Operator (=)
  3. SQL Greater Than Operator (>)
  4. SQL Less Than Operator (<)

Answer (Detailed Solution Below)

Option 2 : SQL Equal Operator (=)

SQL Question 3 Detailed Solution

Explanation: Using SQL Equal Operator from SQL Comparison Operators, we can find the data that matches our query.

Top SQL MCQ Objective Questions

SQL Question 4:

Using which SQL Comparison Operator can we find the data that matches our query?

  1. SQL Not Equal Operator (!=)
  2. SQL Equal Operator (=)
  3. SQL Greater Than Operator (>)
  4. SQL Less Than Operator (<)

Answer (Detailed Solution Below)

Option 2 : SQL Equal Operator (=)

SQL Question 4 Detailed Solution

Explanation: Using SQL Equal Operator from SQL Comparison Operators, we can find the data that matches our query.

SQL Question 5:

The SQL keyword _______ is used with wildcards.

  1. LIKE
  2. IN
  3. NOT IN
  4. DISTINCT

Answer (Detailed Solution Below)

Option 1 : LIKE

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?

  1. ALTER TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)
  2. ADD TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)
  3. ALTER TABLE table_name REFERENCES referenced_table_ name(attribute name) ADD FOREIGN KEY (attribute name)
  4. MODIFY TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)

Answer (Detailed Solution Below)

Option 1 : ALTER TABLE table_name ADD FOREIGN KEY(attribute name) REFERENCES referenced_table_name(attribute name)

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.
Get Free Access Now
Hot Links: teen patti master apk teen patti wealth teen patti game - 3patti poker teen patti casino download