1. What is SQL?
SQL (Structured Query Language) is a programming language used to manage and manipulate relational databases. It allows users to create, retrieve, update, and delete data stored in database tables.
2. What is a Database?
A database is an organized collection of data that can be easily accessed, managed, and updated.
3. What is a Table in SQL?
A table is a structure in a database that stores data in rows and columns.
4. What is a Row?
A row represents a single record in a table.
5. What is a Column?
A column represents a specific attribute of the data stored in a table.
6. What is a Primary Key?
A primary key is a column or group of columns used to uniquely identify each row in a table.
7. What is a Foreign Key?
A foreign key is a column that creates a relationship between two tables.
8. What is DBMS?
DBMS (Database Management System) is software that allows users to create and manage databases.
9. What is RDBMS?
RDBMS (Relational Database Management System) stores data in tables with relationships between them.
10. What are SQL Commands?
SQL commands are instructions used to communicate with databases to perform operations such as retrieving or updating data.
11. What are the Types of SQL Commands?
- DDL – Data Definition Language
- DML – Data Manipulation Language
- DCL – Data Control Language
- TCL – Transaction Control Language
12. What is DDL?
DDL commands define database structure. Example: CREATE, ALTER, DROP.
13. What is DML?
DML commands manipulate data in tables. Example: INSERT, UPDATE, DELETE.
14. What is DCL?
DCL commands control database permissions. Example: GRANT, REVOKE.
15. What is TCL?
TCL commands manage database transactions. Example: COMMIT, ROLLBACK.
16. What is the CREATE command?
CREATE command is used to create a database or table.
CREATE TABLE Students ( ID INT, Name VARCHAR(50), Age INT );
17. What is INSERT command?
INSERT command adds new records into a table.
INSERT INTO Students VALUES (1,'Rahul',21);
18. What is SELECT command?
SELECT command retrieves data from a database.
SELECT * FROM Students;
19. What is UPDATE command?
UPDATE command modifies existing records.
UPDATE Students SET Age = 22 WHERE ID = 1;
20. What is DELETE command?
DELETE command removes records from a table.
DELETE FROM Students WHERE ID = 1;
21. What is WHERE clause?
WHERE clause filters records based on conditions.
22. What is ORDER BY?
ORDER BY sorts the result in ascending or descending order.
SELECT * FROM Students ORDER BY Age DESC;
23. What is GROUP BY?
GROUP BY groups rows with the same values.
24. What is HAVING clause?
HAVING is used to filter grouped results.
25. What is DISTINCT?
DISTINCT removes duplicate values from results.
SELECT DISTINCT City FROM Customers;
26. What is JOIN in SQL?
JOIN combines rows from multiple tables based on related columns.
27. Types of JOIN
- INNER JOIN
- LEFT JOIN
- RIGHT JOIN
- FULL JOIN
28. What is INNER JOIN?
Returns matching records from both tables.
SELECT * FROM Orders INNER JOIN Customers ON Orders.CustomerID = Customers.ID;
29. What is LEFT JOIN?
Returns all records from left table and matching records from right table.
30. What is RIGHT JOIN?
Returns all records from right table and matching from left table.
31. What is FULL JOIN?
Returns all records when there is a match in either table.
32. What is a Subquery?
A query inside another query.
33. What is a View?
A view is a virtual table based on SQL query results.
34. What is an Index?
An index improves database search speed.
35. What is a Constraint?
Constraints enforce rules on data in tables.
36. Types of Constraints
- NOT NULL
- UNIQUE
- PRIMARY KEY
- FOREIGN KEY
- CHECK
- DEFAULT
37. What is NOT NULL?
Ensures column cannot store NULL values.
38. What is UNIQUE constraint?
Ensures all values in column are unique.
39. What is DEFAULT constraint?
Assigns default value when no value is provided.
40. What is CHECK constraint?
Ensures values satisfy a condition.
41. What is AUTO_INCREMENT?
Automatically generates numeric values.
42. What is LIMIT?
Limits number of rows returned.
43. What is COUNT()?
Counts number of rows.
44. What is SUM()?
Calculates total sum.
45. What is AVG()?
Calculates average value.
46. What is MIN()?
Returns smallest value.
47. What is MAX()?
Returns largest value.
48. What is UNION?
Combines results from multiple SELECT queries.
49. Difference between UNION and UNION ALL?
UNION removes duplicates while UNION ALL keeps duplicates.
50. What is Transaction?
A transaction is a sequence of operations executed as a single unit.
51. What are ACID Properties in SQL?
ACID properties ensure reliable database transactions.
- Atomicity – Transaction is completed fully or not at all.
- Consistency – Database remains in a valid state before and after transaction.
- Isolation – Transactions run independently.
- Durability – Once committed, data remains permanently.
52. What is Normalization?
Normalization is the process of organizing data in a database to reduce redundancy and improve data integrity.
53. What is Denormalization?
Denormalization is the process of combining tables to improve read performance at the cost of redundancy.
54. What is First Normal Form (1NF)?
A table is in 1NF when:
- Each column contains atomic values.
- Each record is unique.
55. What is Second Normal Form (2NF)?
A table is in 2NF when:
- It is in 1NF
- All non-key attributes depend fully on the primary key.
56. What is Third Normal Form (3NF)?
A table is in 3NF when:
- It is in 2NF
- No transitive dependency exists.
57. What is BCNF?
Boyce-Codd Normal Form is an advanced version of 3NF where every determinant must be a candidate key.
58. What is a Stored Procedure?
A stored procedure is a precompiled SQL program stored in the database and executed when required.
CREATE PROCEDURE GetStudents AS SELECT * FROM Students;
59. What is a Trigger?
A trigger is a special stored procedure that automatically executes when an event such as INSERT, UPDATE, or DELETE occurs.
60. What is a Cursor?
A cursor allows row-by-row processing of query results.
61. What is a Temporary Table?
A temporary table stores data temporarily during a session.
CREATE TEMP TABLE TempStudents ( ID INT, Name VARCHAR(50) );
62. What is a Self Join?
A self join is when a table joins with itself.
SELECT A.Name, B.Name FROM Employees A, Employees B WHERE A.ManagerID = B.ID;
63. What is a Cross Join?
Cross join returns the Cartesian product of two tables.
64. What is an Index in SQL?
An index improves the speed of data retrieval operations.
65. What are the Types of Index?
- Clustered Index
- Non-Clustered Index
66. What is a Clustered Index?
A clustered index sorts and stores the data rows in the table based on the key values.
67. What is a Non-Clustered Index?
A non-clustered index stores pointers to data rows instead of storing actual data.
68. Difference between View and Table?
- Table stores actual data.
- View is a virtual table based on a SQL query.
69. What is a SQL Function?
A function performs operations on data and returns a value.
70. Types of SQL Functions
- Aggregate Functions
- Scalar Functions
71. What are Aggregate Functions?
Aggregate functions perform calculations on multiple rows.
- COUNT()
- SUM()
- AVG()
- MIN()
- MAX()
72. What are Scalar Functions?
Scalar functions operate on a single value and return one result.
73. What is SQL Injection?
SQL Injection is a security vulnerability where attackers insert malicious SQL queries.
74. How to Prevent SQL Injection?
- Use prepared statements
- Use parameterized queries
- Validate user input
75. What is Database Backup?
Database backup is a copy of the database stored to prevent data loss.
76. What is Data Integrity?
Data integrity ensures accuracy and consistency of data.
77. What is Referential Integrity?
Referential integrity ensures relationships between tables remain valid.
78. What is a Composite Key?
A composite key is formed by combining two or more columns to uniquely identify records.
79. What is a Candidate Key?
A candidate key is a column that can qualify as a primary key.
80. What is an Alternate Key?
An alternate key is a candidate key that is not selected as the primary key.
81. What is a Surrogate Key?
A surrogate key is an artificial key generated automatically.
82. Difference between DELETE and TRUNCATE?
- DELETE removes rows one by one and can be rolled back.
- TRUNCATE removes all rows instantly and cannot be rolled back.
83. Difference between TRUNCATE and DROP?
- TRUNCATE deletes data but keeps table structure.
- DROP deletes the table structure completely.
84. Difference between WHERE and HAVING?
- WHERE filters rows before grouping.
- HAVING filters rows after grouping.
85. Difference between JOIN and SUBQUERY?
JOIN combines tables while subquery executes inside another query.
86. Advantages of Index?
- Faster query execution
- Improved database performance
87. What is SQL Performance Tuning?
SQL performance tuning improves query efficiency by optimizing indexes and queries.
88. What is an Execution Plan?
An execution plan shows how the database engine executes a SQL query.
89. What are SQL Data Types?
Data types define the type of data stored in a column.
- INT
- VARCHAR
- DATE
- FLOAT
90. Difference between CHAR and VARCHAR?
- CHAR has fixed length.
- VARCHAR has variable length.
91. What is NULL?
NULL represents missing or unknown data.
92. What is NOT NULL?
NOT NULL ensures a column cannot contain NULL values.
93. What is CASE Statement?
CASE statement works like IF-ELSE in SQL.
SELECT Name, CASE WHEN Age > 18 THEN 'Adult' ELSE 'Minor' END FROM Students;
94. What is IF condition in SQL?
IF condition allows conditional logic in SQL procedures.
95. What is MERGE Statement?
MERGE statement combines INSERT, UPDATE, and DELETE operations.
96. What is Database Security?
Database security protects database from unauthorized access.
97. What is Role Management?
Roles define permissions for groups of users.
98. What is GRANT Command?
GRANT gives database access permissions.
GRANT SELECT ON Students TO User1;
99. What is REVOKE Command?
REVOKE removes database permissions.
100. What is Data Warehouse?
A data warehouse is a large system used for data analysis and reporting.
📢 Join Our WhatsApp Channel
💼 Get Daily IT Job Updates, Interview Preparation Tips & Instant Alerts directly on WhatsApp.
👉 Join WhatsApp Now📢 Join Our Telegram Channel
💼 Get Daily IT Job Updates, Interview Tips & Exclusive Alerts directly on Telegram!
👉 Join Telegram