How to write fast insert statement

  • how do you do an insert into table <A> select b.1, c.2 from b, c, where...

    statement such that it writes minimal to transaction log.. performancewise.. it is faster? Assume A has just been created with no contents, or just been truncated

    i know that instead of delete all records in a table you can simpily truncate it.. truncate the table won't logs transaction logs.. are there some kind of simular ways for insert?

  • No, the inserts are always logged. Even if you create a table and then insert the records, or let SQL to create the table with a select into, SQL logs the inserts.

    Depending of your database configuration and the numbers of records to insert, you could try Bulk Inserts or to import the data with DTS or bcp.

  • If you set your recovery mode to "Bulk-Logged Recovery" then select into statements as well as BCPs will be minimally logged compared to Full recovery. This would minimize your logs. However, it is risky because recovery is more difficult if the disk fails. Read BOL on "Bulk-Logged Recovery"

    Darren


    Darren

Viewing 3 posts - 1 through 2 (of 2 total)

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