/*
	RemoteStaleEntries_Discovery_Table

	Mark, this will work for both, OM (SQL Express) and DM (SQL CE).
	Apparently only UPDATE with subquery does not work for SQL CE, but DELETE works.


	After forward merge to Trunk Alex will move that code into RemoteStaleEntries_Discovery_Table.sql upgrade script (override the existing code)
		and reference that file in the Upgrade.xml files of OM and DM.
	
*/
Delete from DiscoveryDeviceZeroConfResponse   where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceZeroConfProperty   where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceWmiNetworkAdapter  where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceWmiData            where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceSshNetworkAdapter  where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceSshData            where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceSnmpOid            where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceSnmpNetworkAdapter where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceSnmpData           where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceSmbData            where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDevicePortInfo           where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceNetbiosData        where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceDnsData            where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceAfpResponse        where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDeviceADComputerEntry    where DeviceGuid not in (select DeviceGuid from Device)
go

Delete from DiscoveryDevice                   where DeviceGuid not in (select DeviceGuid from Device)
go

