New answers tagged sql-server-express
I think this question is suffering from a disconnect between the wording of the title -- How do I check how many rows a query will affect before executing it? -- and the true area of concern. That title is misleading because it is assumes (incorrectly) a behavior that is (or is supposed to be) a consequence of the actual question. Yet, being the question ...
If ExperimentID is the primary key or has unique constraint/index, there is no need to limit the number of rows updated since there will never be more than one row updated. If ExperimentID is not unique by itself, I suggest you add additional criteria to identify the desired row. The TOP approach you provided will limit the number of rows updated for ...
Make sure you have working daily backups of your database. If you are concerned about losing recently created data, take transaction log backups every "x" minutes, where "x" is the maximum amount of work-time you are willing to lose from the database. Is @currentID defined in the app as an integer? If it is defined as a string, and you allow that variable ...
I figured it out. You can use TOP to limit how many rows get acted upon: UPDATE Jobs SET JobStatus = 'Running' --there's also an UPDATE where this is set to 'Completed' WHERE ExperimentID IN (SELECT TOP (1) FROM Jobs WHERE ExperimentID = @currentID ORDER BY ExperimentID ASC);
Top 50 recent answers are included