|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
UPDATE TOP 1In SQL Server 2005, you can use the following command: UPDATE TOP 1...
SQL Server 2000 does not have this feature. Is there a way around this? I tried using a WHERE EXISTS clause, but that didn't work. If you give better specifications, you will probably get a better answer. I
don't know what "tried" or "didn't work" mean and I ave no idea how to correct your UPDATE statement to achieve the desired results. One thought is: SET ROWCOUNT 1; UPDATE ... SET ROWCOUNT 0; However, if the above UPDATE statement affects more than one row, there won't be a straightforward way to control which of those rows is going to be affected by the UPDATE statement. Is there any reason you can't identify the exact row you want to modify? <rzale***@gmail.com> wrote in message Show quote news:1158182799.985520.150740@e3g2000cwe.googlegroups.com... > In SQL Server 2005, you can use the following command: UPDATE TOP 1... > > SQL Server 2000 does not have this feature. Is there a way around > this? I tried using a WHERE EXISTS clause, but that didn't work. > On Wed, 13 Sep 2006 17:32:34 -0400, "Aaron Bertrand [SQL Server MVP]"
<ten.xoc@dnartreb.noraa> wrote: >SET ROWCOUNT 1; Another "gotcha" on this one is that if a trigger fires because of the>UPDATE ... >SET ROWCOUNT 0; > >However, if the above UPDATE statement affects more than one row, there >won't be a straightforward way to control which of those rows is going to be >affected by the UPDATE statement. Is there any reason you can't identify >the exact row you want to modify? update any actions in the trigger are subject to the ROWCOUNT limitation too. Roy Harvey Beacon Falls, CT Come on Roy, nobody uses triggers.
Just kidding! Show quote > Another "gotcha" on this one is that if a trigger fires because of the > update any actions in the trigger are subject to the ROWCOUNT > limitation too. The 'set rowcount 1' statement will work in my case.
Thanks Aaron Bertrand [SQL Server MVP] wrote: Show quote > Come on Roy, nobody uses triggers. > > Just kidding! > > > > > Another "gotcha" on this one is that if a trigger fires because of the > > update any actions in the trigger are subject to the ROWCOUNT > > limitation too. rzale***@gmail.com wrote:
> The 'set rowcount 1' statement will work in my case. SET ROWCOUNT 1 will in fact achieve the same as UPDATE TOP 1 - namely> > Thanks > it updates some RANDOM row out of those referred to by the UPDATE statement. But if multiple rows in your table are all equally valid for this update then you should ask yourself whether a) your table has redundant data OR b) your specification is wrong/incomplete. -- David Portas, SQL Server MVP Whenever possible please post enough code to reproduce your problem. Including CREATE TABLE and INSERT statements usually helps. State what version of SQL Server you are using and specify the content of any error messages. SQL Server Books Online: http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx -- On Wed, 13 Sep 2006 17:39:19 -0400, "Aaron Bertrand [SQL Server MVP]"
<ten.xoc@dnartreb.noraa> wrote: >Come on Roy, nobody uses triggers. Except to send emails, of course. Reading these groups that appears> >Just kidding! to be a popular use for triggers. >> Another "gotcha" on this one is that if a trigger fires because of the That particular gotcha was a more common issue back in the>> update any actions in the trigger are subject to the ROWCOUNT >> limitation too. bad-old-days when we had triggers but didn't have DRI or TOP, so a trigger implementing cascading deletes the hard way was pretty vulnerable. Roy InSQL Server 2005 you can do
WITH someCTE AS ( SELECT *, ROW_NUMBER() OVER(ORDER BY col1 DESC) AS RowNum FROM dbo.Tables ) UPDATE someCTE SET coltobeupdated = ...... WHERE RowNum <= 3; <rzale***@gmail.com> wrote in message Show quote news:1158182799.985520.150740@e3g2000cwe.googlegroups.com... > In SQL Server 2005, you can use the following command: UPDATE TOP 1... > > SQL Server 2000 does not have this feature. Is there a way around > this? I tried using a WHERE EXISTS clause, but that didn't work. > |
|||||||||||||||||||||||