Thursday, February 9, 2012

@@rowcount

I want to do something like this.
SELECT *
FROM dbo.Contact [C]
-- If any rows are returned then return to front end.
IF @.@.rowcount > 0
Begin
GOTO FinishSuccessModule
End
-- But i had doubt here
We will never be sure that @.@.RowCount is giving the row count of the query
mentioned above since in a heavy concurrent scenario (as we have in our db
and its growing since our user base is also growing) before your query and
the checking of @.@.RowCount there might be another select fired by another
process or transaction which updates @.@.Rowcount which in turn give you
incorrect values.
how can we implement the same functionality using some other way, i dont
want If exists as there are around 6-7 conditions which are totally
select..if any one of them return record then come out else continue with
other sql st.
does @.@.rowcount create issues as mentioned above and second can we avoid
that using some other functionality.
--
Sanjay
--
SanjayNo, rowcount is safe.
Bojidar Alexandrov
"Sanjay" <Sanjay@.discussions.microsoft.com> wrote in message
news:7276DE0A-F23B-403B-BEE5-C83E51FA71FC@.microsoft.com...
> I want to do something like this.
> SELECT *
> FROM dbo.Contact [C]
> -- If any rows are returned then return to front end.
> IF @.@.rowcount > 0
> Begin
> GOTO FinishSuccessModule
> End
> -- But i had doubt here
> We will never be sure that @.@.RowCount is giving the row count of the
query
> mentioned above since in a heavy concurrent scenario (as we have in our db
> and its growing since our user base is also growing) before your query and
> the checking of @.@.RowCount there might be another select fired by another
> process or transaction which updates @.@.Rowcount which in turn give you
> incorrect values.
> how can we implement the same functionality using some other way, i dont
> want If exists as there are around 6-7 conditions which are totally
> select..if any one of them return record then come out else continue with
> other sql st.
> does @.@.rowcount create issues as mentioned above and second can we avoid
> that using some other functionality.
> --
> Sanjay
> --
> Sanjay|||If all you need to know is are "any" rows returned and don't care how many,
I would change the initial query to SELECT TOP 1 * FROM dbo.Contact (C). If
your contact table gets thousands of rows, why go thru and read them all
when you just need to know "do I get back at least 1 row"? And to be more
specific, you don't need a SELECT *. Pick one narrow column for your
select. Something like select top 1 ContactID from dbo.contact (c). This
is a lot more efficient.
"Bojidar Alexandrov" <bojo_do_not_spam@.kodar.net> wrote in message
news:eWegGSspEHA.3244@.tk2msftngp13.phx.gbl...
> No, rowcount is safe.
> Bojidar Alexandrov
> "Sanjay" <Sanjay@.discussions.microsoft.com> wrote in message
> news:7276DE0A-F23B-403B-BEE5-C83E51FA71FC@.microsoft.com...
> > I want to do something like this.
> > SELECT *
> > FROM dbo.Contact [C]
> > -- If any rows are returned then return to front end.
> > IF @.@.rowcount > 0
> > Begin
> > GOTO FinishSuccessModule
> > End
> > -- But i had doubt here
> > We will never be sure that @.@.RowCount is giving the row count of the
> query
> > mentioned above since in a heavy concurrent scenario (as we have in our
db
> > and its growing since our user base is also growing) before your query
and
> > the checking of @.@.RowCount there might be another select fired by
another
> > process or transaction which updates @.@.Rowcount which in turn give you
> > incorrect values.
> >
> > how can we implement the same functionality using some other way, i dont
> > want If exists as there are around 6-7 conditions which are totally
> > select..if any one of them return record then come out else continue
with
> > other sql st.
> >
> > does @.@.rowcount create issues as mentioned above and second can we avoid
> > that using some other functionality.
> > --
> > Sanjay
> > --
> > Sanjay
>

No comments:

Post a Comment