Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Check if PK value is in table
Message
From
08/12/2005 17:08:19
Keith Payne
Technical Marketing Solutions
Florida, United States
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01076415
Message ID:
01076418
Views:
26
This message has been marked as a message which has helped to the initial question of the thread.
>Is this (see code snippet below) the most efficient way to check if there is a row in the table with a given PK value?
>
>
>IF ( SELECT COUNT(*) FROM MyTable WHERE PkId = @PkId ) < 1
>BEGIN
>	RAISERROR('The record you are looking for aint there.',16,1)
>END
>
>
>Einar
IF NOT EXISTS(SELECT [PK] FROM [MyTable] WHERE [PK] = @PK) ...
If this query is used a lot, there should be a nonclustered index on PK.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform