Physical Address
Haryana ,India
Physical Address
Haryana ,India

In Part-1 we covered the SQL basics like keys, joins, and queries. Now, let’s move a step ahead. In this second part, we’ll explore slightly deeper concepts like subqueries, normalization, transactions, stored procedures, and more — but don’t worry, we’ll keep everything beginner-friendly.
A subquery is just a query inside another query. Think of it as asking one question to help answer another.
Example:
“Find employees working in the Sales department.”
SELECT name
FROM employees
WHERE department_id = (SELECT id FROM departments WHERE name = 'Sales');
Here, the inner query finds the department ID for “Sales,” and the outer query finds employees in that department.
Normalization is a method of organizing data so that it’s clean, avoids repetition, and maintains accuracy.
For example, instead of storing a customer’s address in 10 different tables, you store it once and link it with an ID.
This makes data easier to maintain and update.
Denormalization is the opposite of normalization. It combines tables to make reading data faster — even though it may create some duplicates.
Think of it like keeping both “raw mangoes” and “sliced mangoes” in your fridge. It takes extra space, but it’s quicker when you need a ready-to-eat slice.
Used mainly in data warehouses where speed is more important than storage.
A transaction is a group of SQL operations that work together as one.
For example, when you transfer money:
If either step fails, the whole transaction fails.
SQL follows ACID properties:
A stored procedure is like a reusable recipe stored in the database. Instead of writing the same code again and again, you save it once and run it whenever needed.
Benefits:
NULL means no value. It’s not zero, not blank, just unknown.
This way, if the phone number is missing, it shows “Not Provided.”
Example:
A view is like a saved query. You don’t copy the whole data, you just create a “virtual table” that shows results from a query.
Uses:
A trigger is an automatic action that runs when something happens in a table.
Examples:
Aggregate functions take multiple rows and return a single value.
Often used with GROUP BY to group results, like:
SELECT department, AVG(salary)
FROM employees
GROUP BY department;
This part focused on slightly advanced SQL concepts — subqueries, normalization, transactions, stored procedures, views, and more. These are the exact areas interviewers love to test. Practice them with examples, and you’ll be ready for almost any SQL interview.
Q1: Can I skip normalization?
Not really. For small projects, maybe yes. But in real jobs, normalization is key to keeping data accurate.
Q2: Do I need to memorize queries?
No. Understand the logic — once you know the “why,” the “how” is easy to recall.
Q3: Are stored procedures still used in modern databases?
Yes! They’re widely used for performance and security reasons.
Q4: Is UNION slower than UNION ALL?
Yes, because UNION has to check and remove duplicates, while UNION ALL doesn’t.
Q5: Can I use views instead of tables?
Views don’t store data, they just show it. So they’re great for simplifying queries, but not a replacement for tables.