Thursday, May 21, 2009

How to insert records from te one table to another table in SQL

Hi Guys,

Last time i watch in the forums, one gentleman ask the question , how to insert records to one table from the another table in Sql Server.

This actually simple. and we can do this two ways.

1.normal way

insert into desttableName select * from databaseName.dbo.sourceTableName;


2.You can use the OpenRowSet also

INSERT INTO YourTableName

SELECT *

FROM OPENROWSET(BULK 'SQLNCLI', 'Server=(local);Trusted_Connection=yes;', 'SELECT Columns FROM Database.Schema.Tablename ORDER BY columns)


Thank you
Keep It Watch

1 comment:

  1. If you want to create a temporary table which contains few records from another table, you can create and insert the records in one step as below.

    create table aa_tmp AS
    select *
    from inventory_part_tab
    where contract = 'A-S1';

    ReplyDelete