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.
| 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)GOCREATE INDEX IDX_IsTransB ON tblTransA(isTransB)WITH PAD_INDEX, FILLFACTOR=90GOCREATE TABLE tblTransB( TransID int NOT NULL PRIMARY KEY, TransIDA int NOT NULL, TransDate smalldatetime, TransValue decimal(12,2) )GOMy Question is :which faster with 100000 sample records1. 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 statement2. 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 statementthank'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 ScanHow about:SELECT * FROM Table1 LEFT JOIN Table 2ON Table1.id = Table2.idWHERE Table2.id IS NULLBrett8-) |
 |
|
|
|
|
|
|
|