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 2005 Forums
 Transact-SQL (2005)
 take the different between 2 tables

Author  Topic 

avipenina
Starting Member

44 Posts

Posted - 2007-12-29 : 03:13:44
Hi,

how can i take only the difference between those 2 sql scripts

select distinct database_name
from msdb.dbo.backupset

select name
from sys.databases
where name not in ('master','model','tempdb','msdb')

i tell you what i want to achieve.
i've an ERP program that create new database dynamiclly every 2-3 month.
i want that this newlly created database will be backup once when it's created with full backup but only once on creation.

so i think about query the sys.databases and then query the
msdb.dbo.backupset to see if this database where backup sometime.

or perhaps you have a better idea?

Thx

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2007-12-29 : 10:39:30
select d.name,b.backup_start_date,b.backup_finish_date
from sys.databases d
left outer join msdb.dbo.backupset b
on b.database_name = d.name
where d.name not in ('master','model','tempdb','msdb')


this gives all db info along with backup info if one exists. using this i think you can check whether it was backed up ever. Just check for condition b.database_name IS NULL to get dbs which havent been backed up yet and b.database_name IS NOT NULL to get dbs which have already been backed up.
Go to Top of Page
   

- Advertisement -