Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

SQL MCQs

1. Which SQL command is used to create a new table in a database?

a) INSERT
b) CREATE TABLE
c) UPDATE
d) ALTER

Answer: b) CREATE TABLE

Explanation: The CREATE TABLE command is used to create a new table in a database. It specifies the table name and its columns along with their data types and constraints.


2. What SQL command is used to remove an existing table from a database?

a) DELETE
b) DROP TABLE
c) TRUNCATE TABLE
d) REMOVE

Answer: b) DROP TABLE

Explanation: The DROP TABLE command is used to remove an existing table along with all its data and structure from a database.


3. In SQL, what command is used to modify an existing table structure?

a) MODIFY TABLE
b) ALTER TABLE
c) UPDATE TABLE
d) CHANGE TABLE

Answer: b) ALTER TABLE

Explanation: The ALTER TABLE command is used to modify the structure of an existing table in the database, such as adding, modifying, or dropping columns.


4. Which SQL constraint is used to uniquely identify each record in a table?

a) PRIMARY KEY
b) UNIQUE
c) FOREIGN KEY
d) INDEX

Answer: a) PRIMARY KEY

Explanation: A PRIMARY KEY constraint is used to uniquely identify each record in a table. It ensures that each row in the table is uniquely identifiable.


5. What SQL constraint is used to enforce referential integrity between two tables?

a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
d) INDEX

Answer: b) FOREIGN KEY

Explanation: A FOREIGN KEY constraint is used to enforce referential integrity between two tables by ensuring that the values in a column match the values in another table’s column.


6. Which SQL command is used to remove all rows from a table without deleting its structure?

a) DELETE
b) TRUNCATE TABLE
c) DROP TABLE
d) REMOVE

Answer: b) TRUNCATE TABLE

Explanation: The TRUNCATE TABLE command is used to remove all rows from a table without deleting the table structure itself. It is faster and uses fewer system resources compared to DELETE.


7. In SQL, what is used to improve the retrieval performance of a database table?

a) Primary Key
b) Foreign Key
c) Index
d) Cursor

Answer: c) Index

Explanation: An index is used to improve the retrieval performance of a database table by providing quick access to rows based on the indexed columns.


8. Which SQL construct is used to retrieve and manipulate data row by row?

a) Primary Key
b) Foreign Key
c) Index
d) Cursor

Answer: d) Cursor

Explanation: A cursor is used in SQL to retrieve and manipulate data row by row, allowing for more granular control over data processing operations.


9. What SQL constraint ensures that all values in a column are unique?

a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
d) INDEX

Answer: c) UNIQUE

Explanation: The UNIQUE constraint ensures that all values in a column or a combination of columns are unique, thus preventing duplicate entries in the table.


10. Which SQL command is used to add an index to a table?

a) CREATE INDEX
b) ADD INDEX
c) INDEX TABLE
d) ALTER INDEX

Answer: a) CREATE INDEX

Explanation: The CREATE INDEX command is used to add an index to a table, which improves the performance of data retrieval operations involving the indexed columns.

Leave a Comment