Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Select affected rows
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
omtechguy  
View profile  
 More options Feb 5, 4:19 am
Newsgroups: comp.databases.ms-sqlserver
From: omtechguy <omtech...@gmail.com>
Date: Sun, 5 Feb 2012 01:19:25 -0800 (PST)
Local: Sun, Feb 5 2012 4:19 am
Subject: Select affected rows
Hi,

is there an option to get the identities of the affected rows and not
only a counter that mention the number of the affected rows?

Another question, is there an (NOLOCK) equivalent option for update
statement?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bradbury9  
View profile  
 More options Feb 5, 8:04 am
Newsgroups: comp.databases.ms-sqlserver
From: bradbury9 <ray.bradbu...@gmail.com>
Date: Sun, 5 Feb 2012 05:04:50 -0800 (PST)
Local: Sun, Feb 5 2012 8:04 am
Subject: Re: Select affected rows
On 5 feb, 10:19, omtechguy <omtech...@gmail.com> wrote:

> Hi,

> is there an option to get the identities of the affected rows and not
> only a counter that mention the number of the affected rows?

> Another question, is there an (NOLOCK) equivalent option for update
> statement?

Rows affected for select? there isn't any. But you can declare a table
variable and get into that table the rows affected

There is no sense for nolock with update statements, but you can try
to lock only in a per-row basis, using the rowlock command


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Barrows  
View profile  
 More options Feb 7, 7:30 am
Newsgroups: comp.databases.ms-sqlserver
From: "Bob Barrows" <reb01...@NOSPAMyahoo.com>
Date: Tue, 7 Feb 2012 07:30:48 -0500
Local: Tues, Feb 7 2012 7:30 am
Subject: Re: Select affected rows

omtechguy wrote:
> Hi,

> is there an option to get the identities of the affected rows and not
> only a counter that mention the number of the affected rows?

It depends on the version of SQL Server you are using. SQL 2008 introduced
the OUTPUT clause that you can read about here:
http://msdn.microsoft.com/en-us/library/ms177564.aspx

With earlier versions, you needed to create a trigger that selected the
contents of the temporary inserted table
(http://technet.microsoft.com/en-us/library/ms191300.aspx), but of course,
that would fire for all update statements, not particular ones. Of courrse,
you could crate and then disable it, and for updates where you need to see
the affected rows, enable the trigger before running them, and disable it
after.
http://technet.microsoft.com/en-us/library/ms182706.aspx

> Another question, is there an (NOLOCK) equivalent option for update
> statement?

No. Of course not. This question is really fundamental and leads me to
suspect that you have not done your homework. At the very least, you should
get a book about SQL Server and read it, maybe one of Davidson's, or
Delaney's.
You could attempt to specify ROWLOCK, but that is the default, and if your
query affects too many rows, it will escalate to a table lock anyways.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erland Sommarskog  
View profile  
 More options Feb 7, 7:54 am
Newsgroups: comp.databases.ms-sqlserver
From: Erland Sommarskog <esq...@sommarskog.se>
Date: Tue, 7 Feb 2012 12:54:01 +0000 (UTC)
Local: Tues, Feb 7 2012 7:54 am
Subject: Re: Select affected rows

Bob Barrows (reb01...@NOSPAMyahoo.com) writes:
> It depends on the version of SQL Server you are using. SQL 2008 introduced
> the OUTPUT clause that you can read about here:
> http://msdn.microsoft.com/en-us/library/ms177564.aspx

The OUTPUT clause was added in SQL 2005.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erland Sommarskog  
View profile  
 More options Feb 7, 7:56 am
Newsgroups: comp.databases.ms-sqlserver
From: Erland Sommarskog <esq...@sommarskog.se>
Date: Tue, 7 Feb 2012 12:56:14 +0000 (UTC)
Local: Tues, Feb 7 2012 7:56 am
Subject: Re: Select affected rows

omtechguy (omtech...@gmail.com) writes:
> Another question, is there an (NOLOCK) equivalent option for update
> statement?

You can use NOLOCK in an UPDATE statement, even with the table you are
updating. But of course it does not have any effect.

Overall, NOLOCK is nothing to use at routine, but you need careful
understanding of the consequences. Not only can you happen to read
uncommitted data, but you also fail to read existing and committed data,
which can lead to seriously incorrect results.

If you have problems with locking, you should explore the database setting
READ_COMMITTED_SNAPSHOT. When this setting is in effect, readers to not
block writers and vice versa.

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
bradbury9  
View profile  
 More options Feb 7, 10:03 am
Newsgroups: comp.databases.ms-sqlserver
From: bradbury9 <ray.bradbu...@gmail.com>
Date: Tue, 7 Feb 2012 07:03:15 -0800 (PST)
Local: Tues, Feb 7 2012 10:03 am
Subject: Re: Select affected rows

> > is there an option to get the identities of the affected rows and not
> > only a counter that mention the number of the affected rows?

> It depends on the version of SQL Server you are using. SQL 2008 introduced
> the OUTPUT clause that you can read about here:http://msdn.microsoft.com/en-us/library/ms177564.aspx

Thanks on the OUTPUT clause info, was not aware of it (lots of sql
server 6 and 2000) and seems useful.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bob Barrows  
View profile  
 More options Feb 7, 10:33 am
Newsgroups: comp.databases.ms-sqlserver
From: "Bob Barrows" <reb01...@NOyahooSPAM.com>
Date: Tue, 7 Feb 2012 10:33:31 -0500
Local: Tues, Feb 7 2012 10:33 am
Subject: Re: Select affected rows

Erland Sommarskog wrote:
> Bob Barrows (reb01...@NOSPAMyahoo.com) writes:
>> It depends on the version of SQL Server you are using. SQL 2008
>> introduced the OUTPUT clause that you can read about here:
>> http://msdn.microsoft.com/en-us/library/ms177564.aspx

> The OUTPUT clause was added in SQL 2005.

Of course! My mistake.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »