Results 1 to 9 of 9

Thread: Sql

Hybrid View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2002
    Posts
    29

    Sql

    Hello,

    I dont know if this is the right forum for this question, but I'll give it a try.
    I have created a table in SQL Server - lets call it TempTable in the Temp Database.
    I now want to copy all the data from TempTable to LiveTable (both in the Temp db) using
    a stored proc - ie T-sql. How do I do this? I want to COPY the data, NOT read (select) thru
    each record in Temp and Insert into Live!!

    I know there is some command to do this, but forgot what it is.

    Thx,
    L

  2. #2
    Hyperactive Member ashay's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai,India
    Posts
    278
    hi,

    Insert into Live_Table Select * from Temp_table

    assuming that both the tables have the same structure.

    regds,
    ashay
    "If you should die before me, ask if you could bring a friend."
    - Stone Temple Pilots

  3. #3
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Do you need to do this programatically? Because DTS is the way to accomplish this..
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  4. #4
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    If I'm rebember correctly there is a SELECT INTO statement in SQL Server that you could use to copy data from one table to another, if structure is the same.

  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    I didn't catch that they were in the same database.. I thought you were saying they were in different ones.. yes..

    An example from SQL 2000 Books Online:
    Code:
    SELECT Shippers.*, Link.Address, Link.City,
                       Link.Region, Link.PostalCode
    INTO NewShippers
    FROM Shippers
         JOIN LinkServer.DB.dbo.Shippers AS Link
           ON (Shippers.ShipperID = Link.ShipperID)
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  6. #6
    Hyperactive Member ashay's Avatar
    Join Date
    Feb 2002
    Location
    Mumbai,India
    Posts
    278
    hi,

    My solution also works.Infact i usally use the method in my above post to copy data from one table to another.

    R there any specific advantages of using "Select Into"

    regds,
    ashay
    "If you should die before me, ask if you could bring a friend."
    - Stone Temple Pilots

  7. #7
    Addicted Member
    Join Date
    Oct 2002
    Posts
    174

    Helpful

    Insert into Live_Table(field1,field2,field3) Select field1,field2,field3 from Temp_table. Hope it is helpful for u

  8. #8
    New Member
    Join Date
    Nov 2002
    Location
    India
    Posts
    6
    Actually i am not sure about the t-sql but u can use this code ... if you hvae created the table templive with the same structure then

    you can use this

    insert temlive select * from temp where 1>0 try this ...i will look for a procedure...

    Bye

  9. #9
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Using 'Select Into' removes the requirement that the table structures match. You can assemble the data into the structure you need to insert. Other than that there is no real advantage. If the structures are not the same, 'Select Into' is the way to go.. if they are, your way works fine..
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

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