Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Replace table1 with table2 from different database

Author  Topic 

Windza
Yak Posting Veteran

61 Posts

Posted - 2008-10-23 : 02:40:42
Hi all - I'm looking for an easy way for basic 'copy/paste' type statement to overwrite one table with another from a different database within the same SQL instance... I'm assuming this can be done relatively easily?

Windza
Yak Posting Veteran

61 Posts

Posted - 2008-10-23 : 02:56:02
Nevermind - this seemed to work...
Delete table to replace... then run the following:
SELECT * INTO [DB1].[dbo].[table1] FROM [DB2].[dbo].[table2]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-23 : 02:57:25
due you mean overwrite data? if yes just do below

TRUNCATE TABLE desttable

INSERT INTO desttable
SELECT * FROm srctable

where srctable is table copied from databse and desttable your final table.

Alternatively you could use export-import wizard to copy all data from other db table to your table.


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-10-23 : 04:23:31
quote:
Originally posted by Windza

Nevermind - this seemed to work...
Delete table to replace... then run the following:
SELECT * INTO [DB1].[dbo].[table1] FROM [DB2].[dbo].[table2]


Truncate table [DB1].[dbo].[table1]
INSERT INTO [DB1].[dbo].[table1]
SELECT * FROM [DB2].[dbo].[table2]


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -