MCQs – SQL Basics

MCQ –  Basic SQL multiple-choice questions with answers for written test in software job interview in IT companies.

Q) Which statement is wrong about PRIMARY KEY constraint in SQL?

  1. The PRIMARY KEY uniquely identifies each record in a SQL database table
  2. Primary key can be made based on multiple columns
  3. Primary key must be made of any single columns
  4. Primary keys must contain UNIQUE values.
View Answer
Answer: C
Primary key of a table can be made based on single column or with combination of multiple columns.

Q) Which is/are correct statements about primary key of a table?

  1. Primary keys can contain NULL values
  2. Primary keys cannot contain NULL values.
  3. A table can have only one primary key with single or multiple fields
  4. A table can have multiple primary keys with single or multiple fields
View Answer
Answer: B and C

Q) In existing table, ALTER TABLE statement is used to

  1. Add columns
  2. Add constraints
  3. Delete columns
  4. Delete constrains
  5. All of the above
View Answer
Answer: E
The ALTER TABLE statement is used to add, delete, or modify columns and constraints e.g. UNIQUE KEY, FOREIGN and NOT NULL etc. in an existing table.

Q) SQL Query to delete all rows in a table without deleting the table (structure, attributes, and indexes)

  1. DELETE FROM table_name;
  2. DELETE TABLE table_name;
  3. DROP TABLE table_name;
  4. NONE
View Answer
Answer: A
DELETE FROM table_name; will be used to delete all rows in a table and not the table itself. To delete table itself, DROP command is used.

Leave a Comment