Search code examples
sqlsql-server-2008sql-server-2008-express

Getting data from one database table into another database table


I imported data from MS-Access into a SQL database using the import/export wizard. Now, I have database called

TestDatabase - With a Table called AccessTable - It has 10 columns.

on the same SQL Server, I have another database called SampleDatabase with a table called SampleTable

I want to copy [TESTDATABASE].[dbo].[AccessTable] to [SampleDatabase].[dbo].[SampleTable]

The structure of this table is slightly different. The first two columns don't match but the rest of it match and I want to copy only those matched column.

How to achieve this?

In short: I want 1000 rows from first database insert into second database table.

I am using SQL Server 2008 express for the time being.


Solution

  • You can run this query:

    INSERT INTO [SampleDatabase].[dbo].[SampleTable] (
        field1, field2, field3, field4
    )
    SELECT field1, field2, field3, field4
    FROM [TESTDATABASE].[dbo].[AccessTable];