SQL related interview question and answer for fresher
Here are some common SQL interview questions for freshers along with concise answers to help you prepare effectively:
SQL
What is SQL and why is it used?
SQL (Structured Query Language) is used to communicate with and manage relational databases to perform tasks like querying, updating, and managing data.What are the different types of SQL commands?
DDL (Data Definition Language): CREATE, ALTER, DROP
DML (Data Manipulation Language): SELECT, INSERT, UPDATE, DELETE
DCL (Data Control Language): GRANT, REVOKE
TCL (Transaction Control Language): COMMIT, ROLLBACK
What is the difference between DELETE, TRUNCATE, and DROP?
DELETE removes rows and can be rolled back.
TRUNCATE removes all rows quickly but cannot be rolled back.
DROP deletes entire tables or databases permanently.
What is a primary key?
A unique identifier for each record in a table that cannot be null.What is a foreign key?
A field in one table that refers to the primary key in another table, establishing a relationship.What is normalization? Why is it important?
Organizing data to reduce redundancy and improve data integrity.How do you find duplicate records in a table?
Using GROUP BY with HAVING COUNT(*) > 1.Write a query to fetch employees from the 'HR' department earning more than 50,000.
sql
SELECT * FROM employees WHERE department = 'HR' AND salary > 50000;
What is a JOIN? Name various types.
Combining rows from two or more tables based on related columns. Types: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL JOIN.How do you retrieve unique records from a table?
Use the DISTINCT keyword in SELECT queries.
These questions test your understanding of SQL fundamentals and practical skills needed for database operations. Being able to write simple queries and explain key concepts clearly will help you succeed in fresher SQL interviews.