-2

So the current query I have takes 3 hours to run and realize i need to add non clustered index to run the query fast. So I have added this line of code but still its taking massive time with no result:

create nonclustered index #temp_index 
  on [dbo].#tempData ([class_room]) include ([class_name],[class_floor],[class_building])

This is the current query I have:

IF OBJECT_ID('tempdb..#tempdata') IS NOT NULL DROP TABLE #tempdata

    SELECT [class_room][class_name],[class_floor],[class_building]
    INTO #tempdata
    FROM class_info x

create nonclustered index #temp_index 
   on [dbo].#tempData ([class_room]) include ([class_name],[class_floor],[class_building])

;with cte1 as(
SELECT [class_room][class_name],[class_floor],[class_building]
FROM #tempdata
WHERE class_room <> '')  

select * from cte1
WillardSolutions
  • 2,316
  • 4
  • 28
  • 38
Sahil K
  • 5
  • 1
  • 5

1 Answers1

2

Try to create #tempdata first.

create table #tempdata(
tempid int identity(1,1) not null, --to protect against duplicates
[class_room] varchar(50), 
[class_name] varchar(50),
[class_floor] varchar(50),
[class_building] varchar(50),
primary key (class_room, tempid), -- test this
unique (class_name,class_floor,class_building, tempid) -- or that
)
Alex Kudryashev
  • 9,120
  • 3
  • 27
  • 36