0% found this document useful (0 votes)
50 views8 pages

Top 50 SQL Interview Questions

Sql

Uploaded by

saikiransai9948
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views8 pages

Top 50 SQL Interview Questions

Sql

Uploaded by

saikiransai9948
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

🧠 CORE CS (THEORY)

By Abhishek Rathor

Instagram: code.abhii07 (SYNTAX ERROR)

❖Top 50 SQL Interview Questions

1. What is SQL?

SQL stands for Structured Query Language. It is used to communicate with relational
databases. SQL helps store, retrieve, update, and delete data. It is widely used in database
applications.

2. What are the types of SQL commands?

SQL commands are categorized into DDL, DML, DCL, TCL, and DQL. DDL defines
structure, DML manipulates data. DCL controls access, TCL manages transactions. DQL
retrieves data using SELECT.

3. What is a Database?

A database is an organized collection of data. It stores data in tables for easy access.
Databases reduce redundancy. They support data consistency and security.

4. What is a Table?

A table stores data in rows and columns. Rows represent records, columns represent
attributes. Tables organize data logically. They are basic units of a database.

5. What is a Primary Key?

A primary key uniquely identifies each record in a table. It does not allow null values. Each
table can have only one primary key. It ensures data integrity.
6. What is a Foreign Key?

A foreign key creates a link between two tables. It refers to the primary key of another table.
It maintains referential integrity. Prevents invalid data entry.

7. What is a Candidate Key?

A candidate key is an attribute that can uniquely identify records. A table may have multiple
candidate keys. One is chosen as primary key. Others are alternate keys.

8. What is a Composite Key?

A composite key is formed using two or more columns. Together they uniquely identify a
record. Used when single column is insufficient. Common in junction tables.

9. What is a Super Key?

A super key is a set of one or more columns that uniquely identify rows. It may contain extra
attributes. All candidate keys are super keys. Used to ensure uniqueness.

10. What is NULL?

NULL represents missing or unknown data. It is not equal to zero or empty string. NULL
requires special handling in queries. Comparisons with NULL use IS NULL.

11. What is Normalization?

Normalization organizes data to reduce redundancy. It improves data integrity. Data is


divided into related tables. Normal forms define rules.

12. What is Denormalization?

Denormalization combines tables to improve performance. It increases redundancy


intentionally. Used in read-heavy systems. Trades consistency for speed.
13. What is 1NF?

First Normal Form ensures atomic values in columns. No repeating groups are allowed. Each
column contains single values. It is the base level of normalization.

14. What is 2NF?

Second Normal Form removes partial dependency. It follows 1NF. Non-key attributes
depend on full primary key. Mainly used with composite keys.

15. What is 3NF?

Third Normal Form removes transitive dependency. It follows 2NF. Non-key attributes
depend only on primary key. Improves consistency.

16. What is BCNF?

BCNF is a stronger version of 3NF. Every determinant must be a candidate key. It removes
certain anomalies. Used in complex designs.

17. What is DDL?

DDL stands for Data Definition Language. It defines database structure. Commands include
CREATE, ALTER, and DROP. Changes schema.

18. What is DML?

DML stands for Data Manipulation Language. It modifies table data. Commands include
INSERT, UPDATE, DELETE. Works on records.

19. What is DQL?

DQL stands for Data Query Language. It retrieves data from database. SELECT is main
command. Used for queries.
20. What is DCL?

DCL controls database access. Commands include GRANT and REVOKE. Used for security.
Manages permissions.

21. What is TCL?

TCL manages transactions. Commands include COMMIT and ROLLBACK. Ensures


consistency. Controls transaction flow.

22. What is a View?

A view is a virtual table created from a query. It does not store data physically. Used for
security and simplicity. Helps abstraction.

23. What is an Index?

An index improves query performance. It speeds up data retrieval. Works like a book index.
Uses extra storage.

24. What is a Clustered Index?

A clustered index sorts table data physically. Only one allowed per table. Improves range
queries. Alters data order.

25. What is a Non-Clustered Index?

Non-clustered index stores pointers to data. Does not change physical order. Multiple
allowed. Improves lookup speed.

26. What is a Transaction?

A transaction is a group of SQL operations. Executed as a single unit. Follows ACID


properties. Ensures consistency.
27. What is ACID Property?

ACID stands for Atomicity, Consistency, Isolation, Durability. Ensures reliable transactions.
Prevents data corruption. Essential for DBMS.

28. What is a Join?

Join combines rows from multiple tables. Based on related columns. Used for meaningful
data retrieval. Multiple join types exist.

29. What is Inner Join?

Inner join returns matching records. Non-matching rows are excluded. Most commonly used
join. Improves accuracy.

30. What is Left Join?

Left join returns all rows from left table. Matches from right table included. Unmatched
return NULL. Useful for optional relations.

31. What is Right Join?

Right join returns all rows from right table. Matches from left included. Others return NULL.
Opposite of left join.

32. What is Full Join?

Full join returns all records from both tables. Includes matching and non-matching rows.
Missing values filled with NULL. Useful for comparison.

33. What is Subquery?

A subquery is a query inside another query. Used for complex logic. Can return single or
multiple values. Improves flexibility.
34. What is Stored Procedure?

A stored procedure is a set of SQL statements stored in database. Improves performance and
security. Accepts parameters. Reduces network traffic.

35. What is Trigger?

A trigger executes automatically on events. Events include INSERT, UPDATE, DELETE.


Used to enforce rules. Helps auditing.

36. What is Cursor?

A cursor processes rows one by one. Used in complex operations. Provides row-level control.
Used in stored procedures.

37. What is Constraint?

A constraint enforces rules on data. Ensures data integrity. Types include NOT NULL,
UNIQUE, CHECK. Prevents invalid data.

38. What is UNIQUE Constraint?

UNIQUE ensures distinct values in column. Prevents duplicates. Allows one NULL. Used for
identifiers.

39. What is NOT NULL Constraint?

NOT NULL prevents NULL values. Ensures mandatory data. Improves data completeness.
Used for important fields.

40. What is CHECK Constraint?

CHECK limits allowed values. Ensures valid data. Example age > 18. Used for validation.
41. What is DEFAULT Constraint?

DEFAULT assigns value automatically. Used when no value provided. Improves


consistency. Simplifies insertion.

42. What is GROUP BY?

GROUP BY groups rows by column values. Used with aggregate functions. Helps
summarize data. Common in reports.

43. What is HAVING?

HAVING filters grouped data. Used with GROUP BY. Works like WHERE for aggregates.
Applies conditions.

44. Difference between WHERE and HAVING

WHERE filters rows before grouping. HAVING filters after grouping. WHERE cannot use
aggregates. HAVING can.

45. What is ORDER BY?

ORDER BY sorts query results. Can be ascending or descending. Improves readability. Used
at end of query.

46. What is DISTINCT?

DISTINCT removes duplicate values. Used with SELECT. Improves result accuracy. Shows
unique data.

47. What is UNION?

UNION combines results of queries. Removes duplicates by default. Requires same columns.
Used for merging data.
48. What is UNION ALL?

UNION ALL combines queries including duplicates. Faster than UNION. Same column
requirement. Used when duplicates allowed.

49. What is Alias?

Alias gives temporary name to column or table. Improves readability. Used in queries.
Defined using AS keyword.

50. Why use SQL?

SQL is easy to learn and use. It manages large datasets efficiently. Supports data security and
integrity. Used in almost all applications.

Connect & Share:


Tag us on your success stories:

• Instagram: @code.abhii07
• YouTube: SYNTAX ERROR

You might also like