回答

收藏

RAISERROR()语法意义是什么?

技术问答 技术问答 504 人阅读 | 0 人回复 | 2023-09-14

我刚创造了一个After After Trigger,语法如下:( A; \# w4 V$ j9 W+ U; A* H
Create trigger tgrInsteadTrigger on copytabletoInstead of Insert as     Declare @store_name varchar(30);    declare @sales int;    declare @date datetime;    select @store_name = i.store_name from inserted i    select @sales = i.sales from inserted i    select @date = i.Date from inserted ibegin    if (@sales >    begin        RAISERROR('Cannot Insert where salary > ROLLBACK;        end    else        begin        insert into copytablefrom(store_name,sales,date) values (@store_name,@sales,@date);        Print 'Instead After Trigger Executed      endEnd在上述语法中,我使用了 RAISERROR('Cannot Insert where salary > 1000',16,1)
1 b# U0 o- i: u- P9 R$ K4 h但是当我写RAISERROR('Cannot Insert where salary >1000')它在同一行上犯了错误’)’附近的语法不正确。  a, c0 |8 `- D5 }4 `& _
任何人都可以在这里解释(16、1)的用法。
/ o- [/ l" T8 n# ~7 w% i3 E                                                               
7 o& |: m! \: K+ p    解决方案:                                                               
& `( J! e# `6 E9 ?) {; A                                                                是严重程度error。级别是11-会导致错误SQL。级别越高,级别越严重,transaction该级别应暂停。$ `' @/ z" V6 q1 `) h5 N
在执行以下操作时,您将收到语法错误:" l% ~! K4 ?- ^, P& s( F
RAISERROR('Cannot Insert where salary > 1000').因为你没有指定正确的指定parameters(severity level或state)。7 o9 ]7 g7 y* [, S
如果你想发出警告,而不是警告exception,请使用0-10级。
  f2 m7 n1 S5 N0 }" B从MSDN:1 T8 C3 o  g. e& A
严重程度6 x4 T% l- y: ~
用户定义的严重性水平与消息相关。msg_id引发使用sp_addmessage在创建用户定义的消息时RAISERROR上述指定的严重性将被覆盖sp_addmessage中指定的严重性。任何用户都可以指定从0到18的严重级别。只能由sysadmin具有固定服务器角色的成员或ALTER
3 ^" U- [; ^) ~TRACE权限用户指定从19到25的严重程度。对于19到25的严重程度,需要WITH LOG选项。( N% p. h4 [0 U$ h2 B
状态* n7 z# O, c! a5 b8 n+ v/ ^
是0到255之间的整数。负值或大于255的值会产生错误。如果同一用户定义错误发生在多个位置,使用每个位置的唯一状态号可以帮助找到导致错误的代码部分。这里有一个详细的解释
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则