How to update only first 1000 rows of a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deshaipet
    New Member
    • Feb 2009
    • 16

    How to update only first 1000 rows of a table

    Hi Folks,

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

    Thanks,
    Panditt
  • thesmithman
    New Member
    • Aug 2008
    • 37

    #2
    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

    Code:
    UPDATE table WHERE id<1000
    It's not very fancy but it just might get you through.

    Happy coding!

    Comment

    • Anand Kaushal
      New Member
      • Oct 2010
      • 6

      #3
      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.

      Comment

      Working...