Wednesday, November 9, 2022

What is Difference between Cross join and Full Join in SQL?

 Cross Join:-

CROSS JOIN is also known as the Cartesian product / Cartesian join.

Cross join defines where the number of rows in the first table multiplied by a number of rows in the second table.

Cross Join applies to all columns.


Syntax:

Select * from TableName1

cross join TableName2 ;

Query:

Select * from Table_1

cross join Table_2 ;


Full outer join:


FULL OUTER JOIN combines the results of both left and right outer joins and returns all matched or unmatched rows from the tables on both sides of the join clause.


Syntax:

SELECT *FROM table_1

FULL OUTER JOIN table_2

ON table_1.ColumnName=table_2.ColumnName;


https://medium.com/@patilpoojaif/difference-between-cross-join-vs-full-outer-join-in-sql-server-a882dfc7a3d3

What is SQL Jobs?

 SQL Job?

A Job in SQL Server is a container that allows packaging one or more steps in process that need to be scheduled and executed. We can say, it a series of query actions that SQL Server performs.


https://www.c-sharpcorner.com/UploadFile/ff0d0f/jobs-in-sql-server/

what is SQL Profiler


What is SQL Server Profiler:


The SQL Server Profiler is a performance tool which included with any version of SQL Server. It generally shows how SQL Server accesses the database internally. This tool is used by developers as well as a performance engineering team to analyze which SQL statements take more time to execute. It shows information like, how many reads and writes happened in a transaction, the duration it takes to complete the transaction and information such as that is displayed to show complete information of events occurring in the database end.


Why SQL Server Profiler:

Consider a scenario like, you have made a request to an aspx page, it took 20 seconds to load the page. So it's a performance issue here. Here we need to find out what takes the most amount of time, either in the front end or in the back end. In a single request of an aspx page, there may be n number of database hits based on the functionality; here we need to find out what are all the SQL statements executed in this page request. There the SQL Server Profiler helps you to trace the information on the page request.


How to Use SQL Server Profiler:

Enter the profiler keyword in run command; it will launch the profiler window to connect to the appropriate database. Once the database is connected, the trace will be started; now click the page where you want to trace the information. Stop the trace once the page request is completed; now you can see all the transactions that are performed in that single page request.

the trace information will be displayed in the screen like below.

EventClass - Event Name occurred

TextData - Stored Procedure name or the SQL Statement that is executed

Application Name - Which application invoked this SQL statement

Like that various information will be tracked using the profiler.


Different Scenarios for Using SQL Server Profiler

  1. To find the worst performing queries or stored procedures
  2. To monitor Transact- SQL activity per user
  3. To view the connections involved in a Deadlock


Step By Step to Use Profiler

1.Launch Profiler Tool from Run Command

2.Connect to the appropriate Database

3.Configure the Properties

4.Select the Events that you need

5.

 https://www.c-sharpcorner.com/UploadFile/babu_2082/using-sql-server-profiler/


Tuesday, November 1, 2022

What is difference between Having Clause and Where Clause in SQL?

The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions.

 

Example:

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;


https://www.javatpoint.com/where-vs-having


Comparison BasisWHERE ClauseHAVING Clause
DefinitionIt is used to perform filtration on individual rows.It is used
to perform
 filtration
on groups.
BasicIt is implemented in row operations.It is implemented in
column operations.
Data fetchingThe WHERE clause fetches the specific data from particular rows based on the specified conditionThe HAVING clause
first fetches
the complete data.
It then separates
them according to the
given condition.
Aggregate FunctionsThe WHERE clause does not allow to work with aggregate functions.The HAVING clause can
work with
aggregate functions.
Act asThe WHERE clause acts as a pre-filter.The HAVING clause
acts as a post-filter.
Used withWe can use the WHERE clause with the SELECT, UPDATE, and DELETE statements.The HAVING clause can
only use with the
SELECT statement.
GROUP BYThe GROUP BY clause comes after the WHERE clause.The GROUP BY
clause
comes before
the
HAVING clause.

What is Group By in SQL

 The GROUP BY statement groups rows that have the same values into summary rows, like "find the number of customers in each country".


The GROUP BY statement is often used with aggregate functions (COUNT()MAX()MIN()SUM()AVG()) to group the result-set by one or more columns.

Example:

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;





How to use SQL pagination using LIMIT and OFFSET

  How to extract just a portion of a larger result set from a SQL SELECT. LIMIT n is an alternative syntax to the FETCH FIRST n ROWS ONLY. T...