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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Bulk insertion from one table to another table

Bulk insertion from one table to another table

Scheduled Pinned Locked Moved Database
databasesql-serversysadminperformancequestion
3 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.
  • M Offline
    M Offline
    montu3377
    wrote on last edited by
    #1

    I am having one physical table in which there are 5 columns and 20,000 rows (say first table) and i want to insert those rows into another physical table(say second table) but before insertion all rows into second physical table ,i need to fetch exact ids of each columns from diff-diff. tables from first phy. table and then when i get those ,insert those ids into second physical tables. Here i am planning to use joins to fetch appropriate id but joins can only usefull when i give one row at a time.I don't want to use cursor to fetch single rows becoz it reduce performance. is there any other way like for-loop in sql server 2005 from which i can loop throw one by one records(rows) till end of first physical table? montu3377

    E E 2 Replies Last reply
    0
    • M montu3377

      I am having one physical table in which there are 5 columns and 20,000 rows (say first table) and i want to insert those rows into another physical table(say second table) but before insertion all rows into second physical table ,i need to fetch exact ids of each columns from diff-diff. tables from first phy. table and then when i get those ,insert those ids into second physical tables. Here i am planning to use joins to fetch appropriate id but joins can only usefull when i give one row at a time.I don't want to use cursor to fetch single rows becoz it reduce performance. is there any other way like for-loop in sql server 2005 from which i can loop throw one by one records(rows) till end of first physical table? montu3377

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      While the following will sap performace ... You can write a function that will take in parameters and then return the ID. Then you can write a simple looking select statement. It is heavy on the machine but works fairly well. A man said to the universe: "Sir I exist!" "However," replied the Universe, "The fact has not created in me A sense of obligation." -- Stephen Crane

      1 Reply Last reply
      0
      • M montu3377

        I am having one physical table in which there are 5 columns and 20,000 rows (say first table) and i want to insert those rows into another physical table(say second table) but before insertion all rows into second physical table ,i need to fetch exact ids of each columns from diff-diff. tables from first phy. table and then when i get those ,insert those ids into second physical tables. Here i am planning to use joins to fetch appropriate id but joins can only usefull when i give one row at a time.I don't want to use cursor to fetch single rows becoz it reduce performance. is there any other way like for-loop in sql server 2005 from which i can loop throw one by one records(rows) till end of first physical table? montu3377

        E Offline
        E Offline
        Eric Dahlvang
        wrote on last edited by
        #3

        Can't you do something like this:

        INSERT INTO table2 (field1,field2,field3,field4,field5)
        SELECT (SELECT table3.field2 FROM table3 WHERE table3.field1 = t1.field1) AS field1,
        field2,field3,field4,field5 FROM table1 t1 INNER JOIN table4 t4 ON t1.fieldx = t4.fieldy

        --EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        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