TGViewer
Data Analytics Data Analytics @sqlspecialist · 111K subscribers
Post #2464 10.1K
✅ Top SQL Interview Questions with Answers: Part-4 🧠

31. What are constraints in SQL?
Constraints are rules applied to columns to enforce data integrity:
• PRIMARY KEY – Uniquely identifies each record
• FOREIGN KEY – Ensures referential integrity
• UNIQUE – Ensures all values are different
• NOT NULL – Prevents null values
• CHECK – Restricts values based on condition
• DEFAULT – Assigns a default value

32. What is a composite key?
A composite key is a combination of two or more columns that together uniquely identify a row.
Example: (StudentID, CourseID) in an enrollment table.

33. What are scalar vs table-valued functions?
• Scalar function: Returns a single value (e.g., LEN(), GETDATE())
• Table-valued function: Returns a table/data set and can be used in FROM clause

34. How does indexing affect performance?
Indexes improve read performance (SELECT) by allowing faster searches.
Downsides:
• Slower write operations (INSERT, UPDATE, DELETE)
• Takes additional storage

35. What is data integrity?
Ensures the accuracy, consistency, and reliability of data throughout its lifecycle.
Maintained using constraints, transactions, and normalization.

36. What are triggers in SQL?
Triggers are automatic actions executed in response to certain events on a table (e.g., INSERT, UPDATE, DELETE).
Used for auditing, enforcing rules, or updating related tables.

37. What is a correlated subquery?
A subquery that depends on the outer query for its values. It’s evaluated once for each row of the outer query.
Example:
SELECT name FROM employees e
WHERE salary > (SELECT AVG(salary) FROM employees WHERE dept_id = e.dept_id);

38. What is a cross join?
Combines each row from one table with every row from another — produces Cartesian product.
Used rarely, typically when all combinations are needed.

39. What is UNION vs UNION ALL?
• UNION: Combines two queries, removes duplicates
• UNION ALL: Combines all rows, keeps duplicates
Both require same number and type of columns.

40. Difference between EXISTS and IN
• IN: Checks if a value exists in a list
• EXISTS: Checks if subquery returns any rows
EXISTS is often faster with large subqueries or joins.

💬 Double Tap ❤️ For Part-5
  • ❤ 26
  • 👍 2
More from @sqlspecialist
  1. Oct 12, 20268️⃣ You receive a dataset with inconsistent date formats. How would you clean it? Sample A…
  2. Oct 12, 2026📊 Data Analyst Interview Series — Part 7 Guys, let's continue our Data Analyst Interview…
  3. Oct 12, 2026🚀 𝗪𝗵𝗶𝗰𝗵 𝗧𝗲𝗰𝗵 𝗦𝗸𝗶𝗹𝗹 𝗪𝗶𝗹𝗹 𝗬𝗼𝘂 𝗠𝗮𝘀𝘁𝗲𝗿 𝗶𝗻 𝟮𝟬𝟮𝟲? Want to buil…
  4. Oct 9, 2026“Here, the data is sorted by the second column in descending order and the first five rows…
  5. Oct 9, 2026📊 Data Analyst Interview Series — Part 6 Guys, let's continue our Data Analyst Interview…
  6. Oct 9, 2026🇮🇳 𝗚𝗢𝗩𝗘𝗥𝗡𝗠𝗘𝗡𝗧 𝗢𝗙 𝗜𝗡𝗗𝗜𝗔 — 𝗔𝗜𝗖𝗧𝗘 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝟮𝟬𝟮𝟲 🚀…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →