Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Does it sound OK or there is a better way?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01325494
Message ID:
01325540
Views:
10
>>>Hi everybody,
>>>
>>>Just want to verify if the syntax I used is OK or it can be done better (in Update I want to make sure they don't change name accidentally to already existing)
>>>
>>> IF EXISTS (SELECT * FROM dbo.Registration WHERE FirstName = @FirstName AND LastName = @LastName
>>> AND SiteID = (select SiteID from Registration where RegistrationID = @RegistrationID) and RegistrationID <> @RegistrationID)
>>>
>>>I'm not passing SiteID as a parameter.
>>>
>>>Thanks in advance.
>>
>>
>>IF EXSIST(SELECT * FROM dbo.Registration
>>          INNER JOIN (SELECT SiteId FROM dbo.Registration where RegistrationID = @RegistrationID) Tbl1
>>                ON dbo.Registration.SitedId = Tbl1.SiteId
>>          WHERE dbo.Registration.FirstName = @FirstName AND
>>                dbo.Registration.LastName = @LastName)
>>...
>>
>>Not sure if this is better but I prefer that syntax.
>>You could test both ways, just put execution plan on :-)

>
>Looks better. In VFP the INNER JOIN syntax seems to slightly out-perform the other syntax. See Re: Getting most recent orders? Thread #1249462 Message #1324705 and I would appreciate your tests as well.


I think because WHERE xxx IN (SELECT ...) is executed for every record.
Derived tables are created before main query and then they are just joined and that is why JOINs maybe faster.
That is just my thoughts, NOT SURE ABOUT THAT AT ALL!
:-)
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Reply
Map
View

Click here to load this message in the networking platform