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
 SQL Server Administration (2005)
 Try...Catch

Author  Topic 

honey_191
Starting Member

49 Posts

Posted - 2008-02-06 : 21:01:27
Hi,
Can any body tell me how to write try catch blocks for this code..

my program is :

create procedure res
as

declare @db as varchar(100)
declare @path as varchar(100)
declare @mid as int
declare @mid1 as int
declare @type as char(5)
declare @lname as varchar(100)

set @mid=(select media=max(media_set_id) from resto)

set @path=(select physical_device_name from resto where media_set_id=@mid)

set @db=(select database_name from resto where media_set_id=@mid)

set @type=(select typ from resto where media_set_id=@mid)


set @mid1=(select media=max(media_set_id) from resto1)

set @lname=(select logical_name from resto1 where media_set_id=@mid1)



if @type='D'
begin
restore database @db
from disk=@path
with stats=10,replace,
move '@lname' to 'd:\restore\'
end

else if @type='I'
begin
restore database @db
from disk=@path
with stats=10,norecovery,replace,
move '@lname' to 'd:\restore\'

end

else if @type='L'
begin
restore log @db
from disk=@path
with stats=10,norecovery,replace,
move '@lname' to 'd:\restore\'
end

else
print'operation failed'
   

- Advertisement -