2010-11-12

Restore to another database from DB backup file

RESTORE DATABASE [MyDB2]
FROM DISK = N’D:\Backup\MyDB\MyDB_20080205.bak’
WITH FILE = 1,
MOVE N’MyDB’ TO N’E:\DB\MyDB2.mdf’,
MOVE N’MyDB_log’ TO N’E:\DB\MyDB2.ldf’,
KEEP_REPLICATION, NOUNLOAD, REPLACE, STATS = 10

Copy and insert rows with identity column

SET IDENTITY_INSERT MakeMOney.dbo.ListingHistory ON   <–要設定
insert into MakeMOney.dbo.ListingHistory (ListingItemID,PackageID, ProductID, eBayItemID, Quantity, Sold, Price, HandlingFee, ListingFee, Title, StartTime, EndTime, ItemURL, Duration, Status,                       WarehouseID, HitCount, Lister, LastReviseDate)select  ListingItemID,PackageID, ProductID, eBayItemID, Quantity, Sold, Price, HandlingFee, ListingFee, Title, StartTime, EndTime, ItemURL, Duration, Status,                       WarehouseID, HitCount, Lister, LastReviseDate from ListingHistory where Status=’Active’ and year(StartTime)<=2008
↑insert時要指定欄位