Wednesday, April 20, 2011

How to pull data from one database to another database using sqlsqerver 2005

How to pull data from one database to another database by using sqlsqerver 2005

like ..Exporting data from one and importing to the another.

From stackoverflow
  • Take your pick.

    1. Linked Server/databases.
    2. SSIS
    3. Exporting data from one and importing to the another.
  • In addition to no-one's answers, if the DB's are both SQL Server

    4) Select * into New_Table From Server.Database.Owner.Table

    ck : This is no_one's answer number 1
    MrTelly : A little example goes a long way though, and vec doesn't state whether he's moving between servers.
    marc_s : +1 for giving a nice clean example
  • Based on your comments I understand that both databases are on the same server You can simply do:

    use YourDestinationDatabaseName;
    
    select * into dbo.yourNewTable from YourSourceDatabase.dbo.YourSourceTable
    

    and if you want to insert into table that already exists

    use YourDestinationDatabaseName;
    
    insert into dbo.YourDestinationTable 
    select * from YourSourceDatabase.dbo.YourSourceTable
    

    or more precisely:

    use YourDestinationDatabaseName;
    
    insert into dbo.YourDestinationTable( col1, col2, etc...) 
    select 
        col1a, col2a, etc ... 
    from 
        YourSourceDatabase.dbo.YourSourceTable
    
  • If you have VS 2005, I like this tool, because it generates t-sql: http://www.microsoft.com/downloads/details.aspx?FamilyId=56E5B1C5-BF17-42E0-A410-371A838E570A&displaylang=en

0 comments:

Post a Comment