This query works great in SQL Server 2005 and 2008. How would I write it in SQL Server 2000?
UPDATE TOP 10 myTable
SET myBooleanColumn = 1
OUTPUT inserted.*
Is there any way to do it besides running multiple queries?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To be honest, your query doesn’t really make sense, and I have a hard time understanding your criteria for “great.” Sure, it updates 10 rows, and doesn’t give an error. But do you really not care which 10 rows it updates? Your current
TOPwithoutORDER BYsuggests that you want SQL Server to decide which rows to update (and that’s exactly what it will do).To accomplish this in SQL Server 2000 (without using a trigger), I think you would want to do something like this:
If you want a simple query, then you can have this trigger:
Note that this trigger can’t tell if you’re doing your TOP 10 update or something else, so all users will get this resultset when they perform an update. Even if you filter on IF UPDATE(myBooleanColumn), other users may still update that column.
In any case, you’ll still want to fix your update statement so that you know which rows you’re updating. (You may even consider a
WHEREclause.)