Link to home
Start Free TrialLog in
Avatar of srinivas_ganamur
srinivas_ganamur

asked on

Insert data from one table to another

Hi,

I need to insert data from one table to another table. Currently i am using below statement:

INSERT INTO TABLE_2
SELECT * FROM TABLE_1with (nolock)
GO

The table_1 contains heavy records (in corers) and log file size is growing very high and also it was taking 9-10 hours (1107052852 rows) to insert.

Is there any other way to speed up my insert statement & to minimize log file size growth.

NOTE: 1. table_2 already exist in database with same structure of table_1.
           2. one clustered index and one nonclustered indexes are there in both the tables.
           3. I have tried with Heap table method (no indexes) but no use.

SOLUTION
Avatar of sachiek
sachiek
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of srinivas_ganamur
srinivas_ganamur

ASKER

Hi Sachiek,

The destination table is (table_2) is partitioned table that is table data contains 10 NDF file. I have created indxes on this table. I think can't drop / disable indexes right?

Currently my database in simple recovery model.
Hi Sachiek,

The destination table is (table_2) is partitioned table that is table data contains 10 NDF file. I have created indxes on this table. I think can't drop / disable indexes right?

Currently my database in simple recovery model.
Hi Sachiek,

The destination table is (table_2) is partitioned table that is table data contains 10 NDF file. I have created indxes on this table. I think can't drop / disable indexes right?

Currently my database in simple recovery model.
srinivas_ganamur,

Any commments on my post above..
Hi Rregan17,

Your solution is looking good..i am testing in my local server. After that i will let you know the result.
Sure..
HI RREGAN17

i AM INSERTING DATA USING BULK INSERT (I THINK IT IS FAST AS COMPARED MY INSERT METHOD..RIGHT?)...BUT IT WAS GIVING SYNTAX ERROR

INSERT INTO [dbo].[TABLE_1]

SELECT *

FROM OPENROWSET(BULK 'SQLNCLI', 'Server=(local);Trusted_Connection=yes;',

'SELECT * FROM INSTA_HISTORY.DBO.[dbo].[TABLE_2]')

PLEASE LET ME KNOW WHERE I AM WRONG..
INSERT INTO DATABASE1.[dbo].[TABLE_1]

SELECT *

FROM OPENROWSET(BULK 'SQLNCLI', 'Server=(local);Trusted_Connection=yes;',

'SELECT * FROM DATABASE1.[dbo].[TABLE_2]')
BULK option can be provided only for loading from files and it wont work with another SQL Server table..
And that's why you are obtaining errors.