Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Quickest way to see if a record exists
Message
General information
Forum:
Microsoft SQL Server
Category:
Other
Environment versions
SQL Server:
SQL Server 6.5 and older
Miscellaneous
Thread ID:
01348134
Message ID:
01348139
Views:
32
FYI EXISTS Subqueries: SELECT 1 vs. SELECT *

>There is no need some field to be Primary key to be used in WHERE clause :-).
>So if you want to know if there are records where MyId is equal to some value your select is right. But if you want only to know if these records exsits but you don't need to have recordset based on these records you could use EXISTS() function. It stops execution after the first records is found, so that is the quickest way:
>
>
>IF EXISTS (select * from mytable where myid =lcid)
>    BEGIN
>         print 'Record(s) exists'
>    END
>ELSE
>    BEGIN
>         print 'No record exists'
>    END
>
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform