Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Performance problem need help

SQL Performance problem need help

Scheduled Pinned Locked Moved Database
helpdatabasesysadminperformanceannouncement
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pallav Deshmukh
    wrote on last edited by
    #1

    I have a sql problem. suppose we have two tables ex. A and B which have A1,A2,A3 column and B has B1,B2,B3 Column A1 and B1 are primary key and B2 is foreign key of A(A1) Now B3 has some values in it which i wanted to map with column A3. means i wanted to update column A3 as same as B3 where we have A1=B2 relationship. can we write this in a single sql statement. what i am doing is writing a cursor on table A which one by one retrieve value from table B(B3) and update table A(A3). But problem is that this process is very slow and lock the table at the time it perform operation so all other request will have to wait until this process terminate. otherwise some times sqlserver detects it as a deadlock condition and unconditionally terminate process. So my aim is improve performace of all such processes. Error : Transaction (Process ID 773) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. I wanted some thing like as easy as update A set A.a3= B.b3 where A.a1 =B.b2 which does not work in this case. Table has bulk amount of data i. e. around 10-15 lacks records. I need some alternative solution for many of such process in which i have used same logic am working on. also the database is of prouction server so I cannot kept it busy for long time. Pallav Deshmukh

    W C 2 Replies Last reply
    0
    • P Pallav Deshmukh

      I have a sql problem. suppose we have two tables ex. A and B which have A1,A2,A3 column and B has B1,B2,B3 Column A1 and B1 are primary key and B2 is foreign key of A(A1) Now B3 has some values in it which i wanted to map with column A3. means i wanted to update column A3 as same as B3 where we have A1=B2 relationship. can we write this in a single sql statement. what i am doing is writing a cursor on table A which one by one retrieve value from table B(B3) and update table A(A3). But problem is that this process is very slow and lock the table at the time it perform operation so all other request will have to wait until this process terminate. otherwise some times sqlserver detects it as a deadlock condition and unconditionally terminate process. So my aim is improve performace of all such processes. Error : Transaction (Process ID 773) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. I wanted some thing like as easy as update A set A.a3= B.b3 where A.a1 =B.b2 which does not work in this case. Table has bulk amount of data i. e. around 10-15 lacks records. I need some alternative solution for many of such process in which i have used same logic am working on. also the database is of prouction server so I cannot kept it busy for long time. Pallav Deshmukh

      W Offline
      W Offline
      woudwijk
      wrote on last edited by
      #2

      something like this ??? update a set a.a3 = (SELECT top 1 b.b3 FROM b INNER JOIN a ON a.a1 = b.b1) My second computer is your linux box.

      P 1 Reply Last reply
      0
      • P Pallav Deshmukh

        I have a sql problem. suppose we have two tables ex. A and B which have A1,A2,A3 column and B has B1,B2,B3 Column A1 and B1 are primary key and B2 is foreign key of A(A1) Now B3 has some values in it which i wanted to map with column A3. means i wanted to update column A3 as same as B3 where we have A1=B2 relationship. can we write this in a single sql statement. what i am doing is writing a cursor on table A which one by one retrieve value from table B(B3) and update table A(A3). But problem is that this process is very slow and lock the table at the time it perform operation so all other request will have to wait until this process terminate. otherwise some times sqlserver detects it as a deadlock condition and unconditionally terminate process. So my aim is improve performace of all such processes. Error : Transaction (Process ID 773) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. I wanted some thing like as easy as update A set A.a3= B.b3 where A.a1 =B.b2 which does not work in this case. Table has bulk amount of data i. e. around 10-15 lacks records. I need some alternative solution for many of such process in which i have used same logic am working on. also the database is of prouction server so I cannot kept it busy for long time. Pallav Deshmukh

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #3

        Something like this:

        UPDATE A
        SET A3 = B.B3
        FROM A
        INNER JOIN B ON A.A1 = B.B2


        "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

        P 1 Reply Last reply
        0
        • W woudwijk

          something like this ??? update a set a.a3 = (SELECT top 1 b.b3 FROM b INNER JOIN a ON a.a1 = b.b1) My second computer is your linux box.

          P Offline
          P Offline
          Pallav Deshmukh
          wrote on last edited by
          #4

          Thanks Colin Angus Mackay & woudwijk I am not having good experience of database thanks for help it works. Pallav Deshmukh

          1 Reply Last reply
          0
          • C Colin Angus Mackay

            Something like this:

            UPDATE A
            SET A3 = B.B3
            FROM A
            INNER JOIN B ON A.A1 = B.B2


            "On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question." --Charles Babbage (1791-1871) My: Website | Blog

            P Offline
            P Offline
            Pallav Deshmukh
            wrote on last edited by
            #5

            Thanks Colin Angus Mackay & woudwijk I am not having good experience of SQL. thanks for help!! it works. Pallav Deshmukh

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups