Basically Temporary table in SQL server exists Temporary in Database Server.Which is used to store Subset of Data from other Table.
Mostly Temp table is useful for the store procedure query where we store large amount of record in it and accordingly fetch data from it .
Lets See How to create Temporary table on SQL Server
First We we will use drop command to delete any table exist from that name it will delete automatically if SQL connection breaks
Drop table if exists #Temptable
Now we will Create Temporary table by using the same name i.e use in above query for drop #Temptable.
Basically we use # as Prefix in the name of Temporary Table
We will insert any data in that table and use it accordingly.
Lets See how we will use it in Store Procedure
create proc Sp_GetEmpDetails
as
begin
Drop table if exists #Temptable
create Table #Temptable
(
UserID int,
UserName nvarchar(32),
Address nvarchar(64),
PinCode nvarchar(16),
Designation nvarchar(16),,
Company nvarchar(16),
)
insert into #Temptable
select Username,Address,PinCode ,Designation ,Company
from yourtablename
cross join DesignationtableName
cross join CompanytableName
select * from #Temptable
end
Mostly Temp table is useful for the store procedure query where we store large amount of record in it and accordingly fetch data from it .
Lets See How to create Temporary table on SQL Server
First We we will use drop command to delete any table exist from that name it will delete automatically if SQL connection breaks
Drop table if exists #Temptable
Now we will Create Temporary table by using the same name i.e use in above query for drop #Temptable.
Basically we use # as Prefix in the name of Temporary Table
create Table #Temptable
(
UserID int,
UserName nvarchar(32),
Address nvarchar(64),
)
(
UserID int,
UserName nvarchar(32),
Address nvarchar(64),
)
We will insert any data in that table and use it accordingly.
Lets See how we will use it in Store Procedure
create proc Sp_GetEmpDetails
as
begin
Drop table if exists #Temptable
create Table #Temptable
(
UserID int,
UserName nvarchar(32),
Address nvarchar(64),
PinCode nvarchar(16),
Designation nvarchar(16),,
Company nvarchar(16),
)
insert into #Temptable
select Username,Address,PinCode ,Designation ,Company
from yourtablename
cross join DesignationtableName
cross join CompanytableName
select * from #Temptable
end