Results 1 to 6 of 6

Thread: Mass update of records (SQL Svr 2k) [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Resolved Mass update of records (SQL Svr 2k) [RESOLVED]

    Hi all,

    In one hand I have a table with approx 200,000 records in and a field that needs populating.

    In the other hand I have a text file containing 200,000 identifying fields and the value that should be in the field delimited by a tab.

    Whats the fastest way to do the update?

    I have bad hangover and everything blurry so hope that makes sense :]

    Cheers
    Last edited by tailz; Apr 10th, 2005 at 08:01 AM.

  2. #2
    Fanatic Member Blade's Avatar
    Join Date
    Jan 1999
    Location
    Stoke-on-Trent, UK
    Posts
    527

    Re: Mass update of records (SQL Svr 2k)

    If they are all new rows, use the Import wizard in Enterprise Manager to import straight into the table.

    If they are existing rows that just need updating you can import them via above method into a temp table then do a sql update from query analyser.

    Could probably help a bit more if I knew what was in the text file and the data structure of the table you are trying to put them into.

    Blade

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Mass update of records (SQL Svr 2k)

    Is this a regularly occurring requirement - or a one time need?

    BULK INSERT will easily take you text file and create a table.

    UPDATE ... FROM ... will easily update an existing table, JOINING the new table data for a source of information.

    Give us some table names and field layouts so we can see what you need.

    Another way we do stuff like this all the time (we have to sync mainframe and SQL data nightly at some customers sites) is we have a little VB program that creates a .SQL scripts of UPDATE, INSERT and DELETE statements.

    That will run very slowly for 200,000 entries - but will also work.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Re: Mass update of records (SQL Svr 2k)

    They be existing rows.

    Main table has an identifier of varchar(16) and the field that needs updating is varchar(100).

    In the text file, the first field is the identifier and second field is the value to import.

    Can you give me approx example of the sql update you would do cause thats the bit I cant figure out

    thanks for your help

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Mass update of records (SQL Svr 2k)

    Code:
    Insert into OldTable Select Col1,Col2 From NewTable
    Where Col1 not Exists (Select * From OldTable Where OldTable.Col1=NewTable.Col1)
    I typed that free-hand - don't have SQL here on this PC.

    Code:
    Update OldTable Set Col2=NewTable.Col2
       From OldTable Left Join NewTable on NewTable.Col1=OldTable.Col1
    That should do the update - or something very close to that!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6

    Thread Starter
    Hyperactive Member tailz's Avatar
    Join Date
    Jul 2002
    Posts
    306

    Resolved Re: Mass update of records (SQL Svr 2k)

    ok thats great, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width