xxxxxxxxxx
IF Object_ID('tempdb..#Tablename') IS NOT NULL DROP TABLE #Tablename
Select
*
into
#Tablename
FROM
SampleTable
xxxxxxxxxx
CREATE TABLE #haro_products (
product_name VARCHAR(MAX),
list_price DEC(10,2)
);
xxxxxxxxxx
-- Create temp table
CREATE TEMP TABLE temp_table (
id INT,
name VARCHAR(30)
);
-- Query results to store in the temporary table on the fly
CREATE TEMP TABLE temp_table AS
SELECT column1, column2
FROM table_name;
-- Insert values in temporary table from another table
INSERT INTO temp_table
SELECT column1, column2
FROM another_table
-- Delete temporary table
DROP TABLE IF EXISTS temp_table;
xxxxxxxxxx
CREATE TEMPORARY TABLE temp_table (
id INT,
name VARCHAR(50),
age INT
);
xxxxxxxxxx
-- create Local temporary table i.e single hash(#)
CREATE TABLE #TempTable
( Column1 datatype, column2 datatype……)
INSERT INTO #TempTable
(Column1, column2……)
VALUES ('value 1', 'value 2')
-- 2nd method (Select Into)
SELECT *
INTO #TempTable -- remove this part and it becomes simple select query
FROM SampleTable
WHERE
-- create Global temporary table i.e double hash(##)
CREATE TABLE ##tablename
( Column1 datatype, column2 datatype……)
xxxxxxxxxx
-- CREATE TEMP TABLE
Create Table #MyTempTable (
EmployeeID int
);
-- DROP TEMP TABLE
IF OBJECT_ID('tempdb..#MyTempTable') IS NOT NULL DROP TABLE #MyTempTable
xxxxxxxxxx
-- CREATE TEMP TABLE
Create Table #MyTempTable (
EmployeeID int
);
xxxxxxxxxx
DECLARE @TempTable AS TABLE (Id INT); -- add column that you need with datatype.
xxxxxxxxxx
DECLARE @TempTable AS TABLE(//Mention your columns in here.//)
After that you can insert into this table later.
xxxxxxxxxx
If(OBJECT_ID('tempdb..#temp') Is Not Null)
Begin
Drop Table #Temp
End