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?
- The PRIMARY KEY uniquely identifies each record in a SQL database table
- Primary key can be made based on multiple columns
- Primary key must be made of any single columns
- Primary keys must contain UNIQUE values.
Answer: 3
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?
- Primary keys can contain NULL values
- Primary keys cannot contain NULL values.
- A table can have only one primary key with single or multiple fields
- A table can have multiple primary keys with single or multiple fields
Answer: 2 and 3
Q) In existing table, ALTER TABLE statement is used to
- Add columns
- Add constraints
- Delete columns
- Delete constrains
- All of the above
Answer:5
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)
- DELETE FROM table_name;
- DELETE TABLE table_name;
- DROP TABLE table_name;
- NONE
Answer: 1
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.
Q) Wrong statement about UPDATE keyword is
- If WHERE clause in missing in statement the all records will be updated.
- Only one record can be updated at a time using WHERE clause
- Multiple records can be updated at a time using WHERE clause
- None is wrong statement
Answer: 2
If you omit the WHERE clause, ALL records will be updated.