Results 1 to 2 of 2

Thread: Cursor, is it the only way?

  1. #1
    Kevin Guest

    Cursor, is it the only way?

    Is using cursor the only way to do update in this case.
    I'm updating TableA.ID with TableB.New_id where TableA.ID =
    TableB.ID. TableA has 2.5 million records and TableB has 500,000
    records. Doing it this way bring the system down to it's knees, and
    is taking forever. Any suggestion are welcome.

    declare mrn_cur cursor for
    select dealer_ident, kealer_id
    from dealer
    for read only

    declare @result int
    declare @temp_ident int
    declare @temp_id int
    declare @temp_var int

    open mrn_cur
    fetch mrn_cur into @temp_ident, @temp_id

    while (@@fetch_status = 0)
    begin
    begin transaction
    update label
    set dealer_id = @temp_ident
    where dealer_id = @temp_id
    commit tran
    fetch mrn_cur into @temp_ident, @temp_id
    end
    close mrn_cur
    deallocate mrn_cur
    go



  2. #2
    Gregory Guest

    Cursor, is it the only way? (reply)

    maybe something like this?

    update TableA
    set TableA.ID = TableB.New_ID
    from
    TableB
    where TableA.ID = TableB.ID


    ------------
    Kevin at 5/18/99 6:51:16 AM

    Is using cursor the only way to do update in this case.
    I'm updating TableA.ID with TableB.New_id where TableA.ID =
    TableB.ID. TableA has 2.5 million records and TableB has 500,000
    records. Doing it this way bring the system down to it's knees, and
    is taking forever. Any suggestion are welcome.

    declare mrn_cur cursor for
    select dealer_ident, kealer_id
    from dealer
    for read only

    declare @result int
    declare @temp_ident int
    declare @temp_id int
    declare @temp_var int

    open mrn_cur
    fetch mrn_cur into @temp_ident, @temp_id

    while (@@fetch_status = 0)
    begin
    begin transaction
    update label
    set dealer_id = @temp_ident
    where dealer_id = @temp_id
    commit tran
    fetch mrn_cur into @temp_ident, @temp_id
    end
    close mrn_cur
    deallocate mrn_cur
    go



Posting Permissions

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