Interview Q&A / SQL & DBMS

INTERVIEW Q&A · 69 QUESTIONS

SQL & DBMS interview questions

Joins, keys, normalisation, indexes and transactions for placement and backend interviews.

  1. What is the difference between a primary key, a unique key and a foreign key?

    A primary key uniquely identifies each row and cannot be NULL; a table has only one. A unique key also prevents duplicates, but a table can have many and they usually allow NULL. A foreign key is a column that must match a primary or unique key in another table, which keeps related data consistent.

    BeginnerIn-depth3 min read
  2. What do the NOT NULL, DEFAULT and CHECK constraints do?

    NOT NULL forbids missing values, DEFAULT supplies a value when none is given on insert, and CHECK rejects rows whose values fail a condition. Together they keep bad data out at the database level.

    BeginnerQuick answer1 min read
  3. What do ON DELETE CASCADE, SET NULL and RESTRICT do in a foreign key?

    They define what happens to child rows when the parent row is deleted. CASCADE deletes the children, SET NULL clears their foreign key, and RESTRICT or NO ACTION blocks the delete.

    IntermediateQuick answer1 min read