May 31, 2014 at 3:44 pm
Hi,
I am working with a query. I am looking for an alternative to not exists. Is the exception works instead of not exists
set @studentID = (select stdentID from student where classID = @classID and registeredNumber = @RegisteredNumber);
DELETE TableB WHERE studentID = @studentID
IF NOT EXISTS (SELECT 1 FROM @TableB)
BEGIN
--Moving data from staging tables to main tables when @TableB data is not passed.
INSERT INTO TableB (...)
select (...) from Staging
where studentid= @studentid
else
begin
insert into tableB (..)
select (..)
from TableC
June 1, 2014 at 10:23 am
Why are you looking for an alternative to NOT EXISTS?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 1, 2014 at 10:49 am
I second Gail's question. Why are you looking to replace WHERE NOT EXISTS? Unless there's a performance or resource usage problem with it (which might just need a bit of tweaking), I'd leave it alone.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 1, 2014 at 2:11 pm
I heard that for large table we can't use exist or not-exit will be problem.
June 1, 2014 at 2:19 pm
ramana3327 (6/1/2014)
I heard that for large table we can't use exist or not-exit will be problem.
And you tested that statement and confirmed it to be true?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 1, 2014 at 2:54 pm
Actually I am getting some syntax error while executing that, so in the mean while I posted here to find any alternative.
June 2, 2014 at 1:01 am
First test and see if there's a gram of truth in that statement and whether you even need to be looking for an alternative.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
June 2, 2014 at 6:48 am
ramana3327 (6/1/2014)
Actually I am getting some syntax error while executing that, so in the mean while I posted here to find any alternative.
ramana3327 (5/31/2014)
DELETE TableB WHERE studentID = @studentIDIF NOT EXISTS (SELECT 1 FROM @TableB)
Does @TableB exist or should you be referencing TableB? What's the error message?
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply