Updating multiple rows of a single column

  • Hi there, I have a column that hold about 7000 rows of data, what I need to so is run some tsql that will update all the rows of this column to '20202' ie every row in that column should have a value of 20202.

    how would this be done?

    Many thanks

  • an update statement, without a WHERE statement, would affect every row for the field affected;

    ie:

    UPDATE YOURTABLE  SET MYCOLUMN='20202'

    UPDATE YOURTABLE  SET MYCOLUMN='20202' WHERE STATE='NY'

    typically, you never want to do this(update without a WHERE statement...(what if this was a mission critical accounting table? do you have backups you can roll back to?), but sometimes it has to be done;as you want to update based on some criteria; also, you should always do a select statement with the same criteria to see what you are really going to affect.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Thanks for that, I knew there was a simple way to do it, somebody gave me a cursur script to use and I knew there had to be a simpler way...thanks again

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply