So the current query I have takes long time to run. When i run execution plan, it shows: Table Insert (#tempdata), Cost: 99%. I realized i need to add non clustered index to run the query fast. So I have added this line of code but still there is no difference:
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
This is a bit long for a comment.
Can you explain why you are not just running this code?
SELECT [class_room], [class_name], [class_floor], [class_building]
FROM class_info x
WHERE class_room <> '';
If performance is an issue, I first would recommend getting rid of unnecessary reads and writes -- such as creating a temporary table.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.