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.
Author |
Topic |
deanglen
Yak Posting Veteran
65 Posts |
Posted - 2013-05-03 : 05:19:18
|
HiI have an empty sql table in a database (call it database1) that I want to insert from a backup (call it database2)The SQL script I have have is thisSET IDENTITY_INSERT dbo.MobileDevice ONINSERT INTO dbo.MobileDevice (MobileDeviceID, UserAgent, Name)SELECT * from dbo.MobileDeviceOldSET IDENTITY_INSERT dbo.MobileDevice OFFThis is under the situation where dbo.MobileDeviceOld exists but it does not. What I want to do is insert all the values from dbo.MobileDevice from database 2 into dbo.MobileDevice in database1Is this possible? Never done this before. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-03 : 05:34:05
|
provided both databases are in same server you can use thisUSE database1GOSET IDENTITY_INSERT dbo.MobileDevice ONINSERT INTO dbo.MobileDevice (MobileDeviceID, UserAgent, Name)SELECT * from database2.dbo.MobileDeviceSET IDENTITY_INSERT dbo.MobileDevice OFF ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-03 : 05:37:07
|
If the databases are in different servers you need to setup a linked server connection between them and then use query likeUSE database1GOSET IDENTITY_INSERT dbo.MobileDevice ONINSERT INTO dbo.MobileDevice (MobileDeviceID, UserAgent, Name)SELECT * from Server2.database2.dbo.MobileDeviceSET IDENTITY_INSERT dbo.MobileDevice OFF Server2 is linkedserver connection you set in Server1 to other server------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|