
declare @DeviceGuids table(DeviceGuid uniqueidentifier not null); 
insert into @DeviceGuids select DeviceGuid from Device
Delete from DiscoveryDeviceZeroConfResponse where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceZeroConfProperty where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceWmiNetworkAdapter where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceWmiData where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceSshNetworkAdapter where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceSshData where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceSnmpOid where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceSnmpNetworkAdapter where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceSnmpData where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceSmbData where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDevicePortInfo where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceNetbiosData where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceDnsData where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceAfpResponse where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDeviceADComputerEntry where DeviceGuid not in (select DeviceGuid from @DeviceGuids)
Delete from DiscoveryDevice where DeviceGuid not in (select DeviceGuid from @DeviceGuids)


