0% found this document useful (0 votes)
9 views9 pages

SQL Class 6 PPT

The document outlines key SQL concepts including triggers, pivoting, unpivoting, and performance tuning techniques for query optimization. It provides best practices for optimizing SQL queries and includes a case study with specific questions related to restaurant data analysis. The case study aims to explore various metrics such as restaurant ratings, cuisine types, and pricing across different cities.

Uploaded by

deypriyanka392
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)
9 views9 pages

SQL Class 6 PPT

The document outlines key SQL concepts including triggers, pivoting, unpivoting, and performance tuning techniques for query optimization. It provides best practices for optimizing SQL queries and includes a case study with specific questions related to restaurant data analysis. The case study aims to explore various metrics such as restaurant ratings, cuisine types, and pricing across different cities.

Uploaded by

deypriyanka392
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
You are on page 1/ 9

AGENDA

TRIGGERS IN SQL

PIVOTING AND UNPIVOTING

PERFORMANCE TUNING - Query Optimization in


SQL

CASE STUDY- SWIGGY


TRIGGERS IN SQL
A trigger is a stored procedure that automatically invokes whenever a special event in the database occurs. For example, a trigger can be
invoked when a row is inserted into a specified table or when specific table columns are updated in simple words a trigger is a collection of SQL
statements with particular names that are stored in system memory. It belongs to a specific class of stored procedures that are automatically
invoked in response to database server events. Every trigger has a table attached to it.
PIVOT AND UNPIVOT
Pivoting and unpivoting are techniques used to transform data from a row-wise format to a column-wise format (pivot) or vice versa
(unpivot). These operations are often used when you want to reshape your data for reporting or analysis

• Pivoting :
Pivoting is the process of converting row-level data into column-level data. This is useful when you have data in a "long" format, and
you want to summarize it or make it more readable.

• Unpivoting :
Unpivoting is the process of converting column-level data into row-level data. This is useful when you have data in a "wide" format,
and you want to normalize it or make it suitable for further analysis.
SQL Performance Tuning
Performance tuning in SQL involves optimizing the performance of your SQL queries and database operations to ensure they run
efficiently. Poorly performing SQL queries can lead to slow response times, which can negatively impact application responsiveness
and user experience.

METHODS:

• INDEX OPTIMIZATION

• QUERY OPTIMIZATION

• DATABASE DESIGN IMPROVEMENTS

• HARDWARE UPGRADES
Query Optimization in SQL

Best Practices For SQL Query Optimization:

1. Use Where Clause instead of having

2. Avoid Queries inside a Loop

3. Use Select instead of Select *

4. Add Explain to the Beginning of Queries

5. Keep Wild cards at the End of Phrases

6. Use Exist() instead of Count()

7. Create queries with INNER JOIN (not WHERE or cross join)

8. Use LIMIT to sample query results

9. Consider denormalizing data for frequently used reports to reduce the need for complex joins

10. Implement caching mechanisms (e.g., in-memory caching or database query caching) to store and reuse query results for a
certain period.

11 Try to run your query during off-peak hours.


CASE STUDY
CASE STUDY

QUESTIONS

01 HOW MANY RESTAURANTS HAVE A RATING GREATER THAN 4.5?

02 WHICH IS THE TOP CITY WITH THE HIGHEST NUMBER OF RESTAURANTS?

03 HOW MANY RESTAURANTS SELL( HAVE WORD "PIZZA" IN THEIR NAME)?

04 WHAT IS THE MOST COMMON CUISINE AMONG THE RESTAURANTS ?

05 WHAT IS THE AVERAGE RATING OF RESTAURANTS IN EACH CITY?


CASE STUDY

06 WHAT IS THE HIGHEST PRICE OF ITEM UNDER THE 'RECOMMENDED' MENU


CATEGORY FOR EACH RESTAURANT?

07 FIND THE TOP 5 MOST EXPENSIVE RESTAURANTS THAT OFFER CUISINE OTHER
THAN INDIAN CUISINE.

08 FIND THE RESTAURANTS THAT HAVE AN AVERAGE COST WHICH IS HIGHER


THAN THE TOTAL AVERAGE COST OF ALL RESTAURANTS TOGETHER.

09 RETRIEVE THE DETAILS OF RESTAURANTS THAT HAVE THE SAME NAME BUT
ARE LOCATED IN DIFFERENT CITIES.

10 WHICH RESTAURANT OFFERS THE MOST NUMBER OF ITEMS IN THE 'MAIN


COURSE' CATEGORY?
CASE STUDY

11 LIST THE NAMES OF RESTAURANTS THAT ARE 100% VEGEATARIAN IN


ALPHABETICAL ORDER OF RESTAURANT NAME

12 WHICH IS THE RESTAURANT PROVIDING THE LOWEST AVERAGE PRICE FOR ALL
ITEMS?

13 WHICH TOP 5 RESTAURANT OFFERS HIGHEST NUMBER OF CATEGORIES?

14 WHICH RESTAURANT PROVIDES THE HIGHEST PERCENTAGE OF


NON-VEGEATARIAN FOOD?

15 DETERMINE MOST AND LEAST EXPENSIVE CITIES FOR DINING.

16 FIND TOP 2 RATED RESTAURANT IN EACH CITY.

You might also like