WEB开发网
开发学院数据库MSSQL Server 基于SQL Server 的Exception Handling - PART II 阅读

基于SQL Server 的Exception Handling - PART II

 2008-12-06 10:15:28 来源:WEB开发网   
核心提示: 在前面的部分我们说过,sys.messages是可以用于专门存放Error相关的信息:Error number, severity,基于SQL Server 的Exception Handling - PART II(4),state,message等,可以参阅SQL Server Boo

在前面的部分我们说过,sys.messages是可以用于专门存放Error相关的信息:Error number, severity,state,message等。而且他不但可以用于系统与定义error的存储,也可以用于存放我们自定义的Error。更加可喜的是,SQL Server定义了一些built-in stored procedure来用于message的添加、删除和修改:

sp_addmessage [ @msgnum = ] msg_id ,   [ @severity = ] severity , [ @msgtext = ] 'msg'
   [ , [ @lang = ] 'language' ]
   [ , [ @with_log = ] 'with_log' ]
   [ , [ @replace = ] 'replace' ]
  
sp_dropmessage [ @msgnum = ] message_number  [ , [ @lang = ] 'language' ]

sp_altermessage [ @message_id = ] message_number  , [ @parameter = ] 'write_to_log'  , [ @parameter_value = ] 'value'

关于如何使用这些stored procedure,可以参阅SQL Server Books Online。在这里,我同下面的script添加我需要的Error。

sp_addmessage  @msgnum = 50001,@severity = 16,@msgtext = N'This user is already existent' , @replace = 'replace'
GO
sp_addmessage  @msgnum = 50002,@severity = 16,@msgtext = N'This role is already existent', @replace = 'replace'
Go
sp_addmessage  @msgnum = 50003,@severity = 16,@msgtext = N'This user does not exist', @replace = 'replace'
GO
sp_addmessage  @msgnum = 50004,@severity = 16,@msgtext = N'This role does not exist', @replace = 'replace'
GO
sp_addmessage  @msgnum = 50005,@severity = 16,@msgtext = N'This user is already in the role', @replace = 'replace'
GO

上一页  1 2 3 4 5 6 7 8 9  下一页

Tags:基于 SQL Server

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接