Thursday 26 September 2013

Can I access Temporary table of one procedure into another prcocedure in sql server?Is it possible?

  Yes.You can use.
Run following Script :

if exists(select name from sys.procedures where name='sp1')
drop proc sp1
go
create procedure sp1
as
begin

select * from #t1

end
go
Go
if exists(select name from sys.procedures where name='sp2')
drop proc sp2
go
go
create procedure sp2
as
begin
select 'SP1 Table' [Value] into #t1
 exec sp1
end
go
 exec sp2


Friday 13 September 2013

Graphical Query Plan


When SQL Server executes a query it uses a query plan to determine how to access data and complete the query.  SQL Server offers DBAs and developers the ability to see these query plans to assist in query optimization.  Without query plans it would be difficult to figure out how to tune and optimize your queries.

One such version of query plans is Graphical Execution Plans which allows you to see a graphical representation of the processing steps of your query to find optimization opportunities.

The Query Execution Plans describe the steps and the order used to access or modify data in the Microsoft SQL Server database. In this tutorial we will use the terms Execution Plan, Query Plan and Query Execution Plan interchangeably.

Briefly, the Query Plan defines how SQL statements are physically executed by the server. The Query Plan describes the data retrieval and storage methods that are used by the Query Optimizer to execute a specific query. For example, it includes whether the whole table should be read or if an index is used to read a small number of records.

The Execution Plan consists of different operations and each operation has one output which is called the result set. The operations can have one or more inputs such as join operations that have two inputs. Each result set (output) will be the input for the next operation until the SQL statement is finished executing. Therefore the data flow can be drawn as a connection between operators from right to left.

There are many potential ways to execute a query thus SQL Server has to choose the most beneficial one. In the case of very complex queries where there can be many variations, so SQL just picks a plan that is good enough.

The executed Query Plans are also stored in the Procedure Cache, so they can be retrieved and reused if a similar query is executed.

SQL Server can create plans in two ways:

    Actual Execution Plan - created after execution of the query and contains the steps that were performed
    Estimated Execution Plan - created without execution of the query and contains an approximate execution plan

First Database In Sql Server