Top SQL Interview Questions Asked in TCS

10000coders10000coders
3 min read

Bhargav

Top SQL Interview Questions Asked in TCS

Preparing for a TCS interview? Here are some commonly asked SQL questions that will help you understand the key concepts and get ready for success!

1. What is SQL?

SQL (Structured Query Language) is a standard programming language specifically designed for managing and manipulating databases.

2. Difference between DELETE, TRUNCATE, and DROP

| Command | Description | Can be Rolled Back? | Removes Table Structure? | |-----------|-------------|---------------------|---------------------------| | DELETE | Deletes specific rows using WHERE | Yes | No | | TRUNCATE | Deletes all rows (faster) | No | No | | DROP | Deletes entire table | No | Yes |

3. What is a Primary Key?

A Primary Key uniquely identifies each record in a table. It must be unique and not null.

4. What is a Foreign Key?

A Foreign Key is a field in one table that refers to the Primary Key in another table. It helps maintain referential integrity.

5. What is the difference between WHERE and HAVING?

| Clause | Works on | Usage | |--------|----------|-------| | WHERE | Rows | Used before grouping | | HAVING | Groups | Used after grouping (with GROUP BY) |

6. What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL JOIN?

| Type | Description | |-------------|-------------| | INNER JOIN | Returns matching rows from both tables | | LEFT JOIN | All rows from left table + matching rows from right | | RIGHT JOIN | All rows from right table + matching rows from left | | FULL JOIN | All rows when there's a match in one of the tables |

7. What is the difference between UNION and UNION ALL?

  • UNION removes duplicate records.

  • UNION ALL includes all records, including duplicates.

8. What is normalization?

Normalization is the process of organizing data to minimize redundancy. It involves dividing large tables into smaller ones and defining relationships.

9. What are Aggregate Functions?

Aggregate functions perform a calculation on a set of values and return a single value.

  • SUM()

  • AVG()

  • COUNT()

  • MAX()

  • MIN()

10. Difference between CHAR and VARCHAR?

| Type | Description | |--------|-------------| | CHAR | Fixed length | | VARCHAR| Variable length |

11. What is a View?

A View is a virtual table based on the result of a SELECT query. It does not store data physically.

12. What is a Subquery?

A Subquery is a query nested inside another query. It can be used in SELECT, INSERT, UPDATE, or DELETE statements.

13. Explain GROUP BY with an example

SELECT department, COUNT(*) 
FROM employees 
GROUP BY department;

This query counts the number of employees in each department.

14. What is the use of DISTINCT?

It is used to remove duplicate rows from a result set.

SELECT DISTINCT city FROM customers;

15. How to find second highest salary?

SELECT MAX(salary) 
FROM employees 
WHERE salary < (SELECT MAX(salary) FROM employees);

Stay tuned and keep practicing! SQL is all about solving problems efficiently with data.

๐Ÿ’ก Pro Tip: Practice these queries on sample databases like Sakila or AdventureWorks to get real-world experience.

๐Ÿš€ Ready to kickstart your tech career?

๐Ÿ‘‰ Apply to 10000Coders
๐ŸŽ“ Learn Web Development for Free
๐ŸŒŸ See how we helped 2500+ students get jobs

0
Subscribe to my newsletter

Read articles from 10000coders directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

10000coders
10000coders

10000coders offers a structured, mentor-guided program designed to transform absolute beginners into confident, job-ready full-stack developers in 7 months. With hands-on projects, mock interviews, and placement support, it bridges the gap between learning and landing a tech job.