Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 table join

Author  Topic 

Tonekene
Starting Member

6 Posts

Posted - 2014-10-03 : 10:37:14
good morning everyone

I have few tables i join together all the time, and i join it on 7 fields (division, dept, dpdept, dpgroup, dpsector, acct, year) all fields are varchar. all indexed queries run under 2 seconds, it is acceptable and all that.

But i still want to improve it and i would like to know is there a way to somehow hash or combine these fields into one, maybe int tyoe field, and then join on it?

what do u think?
thanks

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-10-03 : 13:23:28
you could use a computed column that concatenates the columns and index that. hashbytes might work too, but be aware that collisions are possible with hashing:

https://dba.stackexchange.com/questions/35219/choosing-the-right-algorithm-in-hashbytes-function

Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2014-10-03 : 16:27:00
You don't need to combine them. Create a single index that has the keys in the order in which you specify them. For example, if you always specify division, it can go first. As long as key values are present in order, SQL can seek to that location to start the search. As soon as even one key value is missing, SQL must scan every index row from that point forward.
Go to Top of Page
   

- Advertisement -