Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm trying to find out how to detect if a backup device exists using T-SQL.

This is how I create my backup device:

EXEC master.dbo.sp_addumpdevice 
    @devtype = N'disk', 
    @logicalname = N'TestTest', 
    @physicalname = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.PTC_SQLPROD\MSSQL\Backup\TestTest.bak'

but I can't find how to detect if it already exists first.

share|improve this question
add comment

migrated from stackoverflow.com Oct 31 '12 at 13:02

This question came from our site for professional and enthusiast programmers.

1 Answer

up vote 0 down vote accepted

The sys.backup_devices table should contain details on existing backup devices, so try checking to see if there's a row there first:

IF NOT EXISTS (SELECT NULL
               FROM   sys.backup_devices
               WHERE  [Name] = N'TestTest'
                      AND [Type] = 2)
  EXEC master.dbo.Sp_addumpdevice
    @devtype = N'disk',
    @logicalname = N'TestTest',
    @physicalname = N'C:\Program Files\Microsoft SQL Server\MSSQL10_50.PTC_SQLPROD\MSSQL\Backup\TestTest.bak'

The documentation for the sys.backup_devices table can be found here: http://msdn.microsoft.com/en-us/library/ms178018%28v=sql.100%29.aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.