日期:2014-05-18 浏览次数:20785 次
try catch : begin try select 1/0 end try begin catch select * from sys.messages where Message_id=@@error and language_id=2052 end catch
------解决方案--------------------
-- 定义要执行的SQL declare @sql varchar(5000) select @sql='use tmptest' -- 用 try.. catch.. begin try exec(@sql) end try begin catch select error_number() as error_number , error_message() as error_message, error_state() as error_state, error_severity() as error_severity end catch -- 结果 error_number error_message error_state error_severity ------------ ---------------------------------------------- ----------- -------------- 911 Database 'tmptest' does not exist. Make sure that the name is entered correctly. 1 16 (1 row(s) affected)