By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,030 Members | 2,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,030 IT Pros & Developers. It's quick & easy.

How to update only first 1000 rows of a table

P: 16
Hi Folks,

I would like to update only first 1000 rows of a table. Can anyone help me with the SQL ?

Thanks,
Panditt
Oct 9 '10 #1
Share this Question
Share on Google+
2 Replies


P: 37
Hi Panditt,
If this is a one-time operation, I would probably use a simple for loop that iterates a thousand times and increments through the record numbers. Alternatively, if your records are numbered sequentially, you could do something like

Expand|Select|Wrap|Line Numbers
  1. UPDATE table WHERE id<1000
It's not very fancy but it just might get you through.

Happy coding!
Oct 10 '10 #2

P: 6
You could also use something like this, in case there are gaps in the sequence and you want to set a particular column to the same value..

UPDATE TABLE SET COL = VALUE
WHERE ID IN (SELECT ID FROM TABLE ORDER BY ID FETCH FIRST 1000 ROWS ONLY);

Thesmithman's options are perfect too btw - depends what you've gotta accomplish.
Oct 10 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.