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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Restore after a date into database

Author  Topic 

john duckworth
Starting Member

2 Posts

Posted - 2006-05-02 : 07:13:10
Hi,

I'm pretty new to SQL and have a problem to restore a database from another server which I have done with the following script:-
< ----------- script ------------------------------- >
RESTORE FILELISTONLY
FROM DISK = 'D:\SQL\MSSQL\BACKUP\database.bak'
RESTORE DATABASE database
FROM DISK = 'D:\SQL\MSSQL\BACKUP\database.bak'
WITH MOVE 'database_data' to 'D:\SQL\MSSQL\BACKUP\database_data.mdf',
MOVE 'database_log' TO 'D:\SQL\MSSQL\BACKUP\database_log.ldf'

GO
< ----------- script ------------------------------- >

I am getting weekly updates of the database via a CD which is a full database backup. I need to be able to just restore the changed data which I can specify a date and time for and add it to the database restore I created from my initial script above. The reason I cannot do a full restore again is that the data, once on our system is getting updated and I need to preserve this.

I have searched Google and Books online and can see no way to do this.

Can anyone help?

nr
SQLTeam MVY

12543 Posts

Posted - 2006-05-02 : 07:23:22
There is no way to do this.
You can restore the backup to another database then copy the data from it if you have some way of knkowing what has been added.

Otherwise you can use things like replication or transaction log backups but if you only have a full backup then you are a bit stuck.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

john duckworth
Starting Member

2 Posts

Posted - 2006-05-02 : 08:51:46
quote:
Originally posted by nr

There is no way to do this.
You can restore the backup to another database then copy the data from it if you have some way of knkowing what has been added.

Otherwise you can use things like replication or transaction log backups but if you only have a full backup then you are a bit stuck.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.



So it looks like the way to go is to restore into a new database and run a query to gather all data from each table from a certain point in time and then use an update query to merge this with the main original database. Sounds complex but I'll hit the reference books to see if I can suss this out. Thanks for your help, it is much appreciated.
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-05-02 : 08:59:52
We have some queries that work sorta like this, which might be what you need:

UPDATE D
SET Column1 = S.Column1,
Column2 = S.Column2,
...
FROM DestinationDatabase.dbo.MyTable AS D
JOIN SourceDatabase.dbo.MyTable AS S
ON S.MyPKColumn = D.MyPKColumn
WHERE (S.Column1 <> D.Column1
OR (S.Column1 IS NULL AND D.Column1 IS NOT NULL)
OR (S.Column1 IS NOT NULL AND D.Column1 IS NULL) )
AND (S.Column2 <> D.Column2
OR (S.Column2 IS NULL AND D.Column2 IS NOT NULL)
OR (S.Column2 IS NOT NULL AND D.Column2 IS NULL) )
...

INSERT INTO DestinationDatabase.dbo.MyTable
(
Column1, Column2, ...
)
SELECT S.Column1, S.Column2, ...
FROM SourceDatabase.dbo.MyTable AS S
WHERE NOT EXISTS
(
SELECT *
FROM DestinationDatabase.dbo.MyTable AS D
WHERE D.MyPKColumn = S.MyPKColumn
)

Couple of caveats:

The "<>" test won't work for TEXT columns (we compare DATA_LENGTH() and CONVERT(varchar(8000), S.MyTextColumn) <> CONVERT(varchar(8000), D.MyTextColumn) to text-compare the first 8,000 characters only (and then only if the DATA_LENGTH() is the same)

Also, if you want to compare case SENSITIVE (and assuming your database is case INsensitive), then you need to use a Binary Collate in the comparison of any char/varchar/text columns

Kristen
Go to Top of Page
   

- Advertisement -