SELECT INTO (without re-creating table)

  • hiya,

    I want to copy all the rows:

    1) FROM  table A

    2) TO table B

    thereby, completely overwriting the rows in table B.

    I am using a SELECT INTO statement, but it seems to want to RE-CREATE the table.I would like to be able to select into an EXISTING table.

    <sql>

    SELECT *

    INTO tblA

    FROM tblB

    </sql>

    Can anyone tell me the simplest way to do this? I don't think I have to use a UDF or anything.

    cheers,

              yogi

     

  • can't you just drop the table B?? and then execute the select .. into

  • You can do something like this :

    TRUNCATE TABLE TableB

    Insert into TableB (Col1, Col2, Col3...) (Select Col1, Col2, Col3 from TableA)

  • hiya,

    well, they both work.Thanks.

    yogi

  • Yes they both work both my version will not cause the sp to recompile. This can be a great time saver if the proc is not performing well... and it's considered best pratice to create the table only once whenever possible.

  • salut Remi,

    thanks for the extra tip

    a plus,

    yogi

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply