0

In my database for somereasons not all table have foreign key then for have a better performance I used a select into (with data filtered) in a temp table , I did this for the tables I'll use for to have a better performance but now....

In the final result when I need do join between those table (temp table can't have foreign key, isn't it?) do not have foreign key I got "Merge Join" (I understand they are caused because my temp table does not have foreign key)

Merge Join

(If you dont see the pic I reupload it at here) https://ibb.co/f0XRHv

angel
  • 4,474
  • 12
  • 57
  • 89
  • 2
    Not exactly sure what your question is (other than improve performance) but you can create indexes on temp tables, which might help with your temp table joins. I think SQL Server will try to create any missing indexes for you on temp tables but you might need a larger number of rows before it decides its worth it. – Doug Knudsen Jul 05 '17 at 00:19
  • Why do you think merge join is bad? – Alex Jul 05 '17 at 02:36
  • @Alex may be is not bad, but if they have foreign key, this will be faster yet. – angel Jul 05 '17 at 15:17

1 Answers1

0

How about using something like suggested in the following answer?

No foreign key restraints on a temporary table? SQL Server 2008

ViKiNG
  • 1,294
  • 2
  • 19
  • 26
  • are they temp tables? can an user with read permission use "use tempdb create table parent ( parent_key int primary key clustered )"?????? – angel Jul 05 '17 at 15:18