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 2000 Forums
 SQL Server Development (2000)
 Index VS JOIN

Author  Topic 

GenerationWithoutName
Starting Member

26 Posts

Posted - 2003-07-11 : 02:16:10
I'm confusing right now.i can't decide which one is faster.well, i have two tables like this:
CREATE TABLE tblTransA
( TransID int NOT NULL PRIMARY KEY,
TransDate smalldatetime,
AssetCost decimal(12,2),
Deposit decimal(12,2),
IsTransB varchar(1) DEFAULT('0') -->'0'=data TransA not in TransB,
-->'1'=data TransA in TransB
)
GO
CREATE INDEX IDX_IsTransB ON tblTransA(isTransB)
WITH PAD_INDEX, FILLFACTOR=90
GO
CREATE TABLE tblTransB
( TransID int NOT NULL PRIMARY KEY,
TransIDA int NOT NULL,
TransDate smalldatetime,
TransValue decimal(12,2)
)
GO
My Question is :
which faster with 100000 sample records
1. SELECT a.TransID, a.TransDate, a.AssetCost, a.Deposit
FROM tblTrans AS a
WHERE NOT EXISTS (SELECT TransIDA FROM tblTransB
WHERE TransIDA=a.TransID)
--or something like left outer join, or not in join statement
2. SELECT a.TransID, a.TransDate, a.AssetCost, a.Deposit
FROM tblTransA AS a
WHERE a.IsTransID='0'
-->if IsTransA='0' then data TransA not in TransB,
-->if IsTransA='1' then data TransA in TransB
it's use index instead of join statement
thank's all gurus

X002548
Not Just a Number

15586 Posts

Posted - 2003-07-11 : 09:28:37
We need to know the distribution of data between the 2 tables, but I believe NOT EXISTS (Or NOT anything) will Scan

How about:

SELECT * FROM Table1
LEFT JOIN Table 2
ON Table1.id = Table2.id
WHERE Table2.id IS NULL



Brett

8-)
Go to Top of Page
   

- Advertisement -