22,301
社区成员




这只是一个占位符
每次出错的时候,系统自动替换了。
你试试
DECLARE @@MIN_LVL tinyint,
@@MAX_LVL tinyint,
@@EMP_LVL tinyint,
@@JOB_ID smallint
SELECT @@MIN_LVl = min_lvl,
@@MAX_LV = max_lvl,
@@ EMP_LVL = i.job_lvl,
@@JOB_ID = i.job_id
FROM employee e, jobs j, inserted i
WHERE e.emp_id = i.emp_id AND i.job_id = j.job_id
IF (@@JOB_ID = 1) and (@@EMP_lVl <> 10)
BEGIN
RAISERROR ('Job id 1 expects the default level of 10.', 16, 1)
ROLLBACK TRANSACTION
END
ELSE
IF NOT @@ EMP_LVL BETWEEN @@MIN_LVL AND @@MAX_LVL)
BEGIN
RAISERROR ('The level for job_id:%d should be between %d and %d.',
16, 1, @@JOB_ID, @@MIN_LVL, @@MAX_LVL)
ROLLBACK TRANSACTION
END
select * from table1 -- 其中col1是主键
col1
-----
1
2
begin try
insert into table1 select '2' -- 制造主键重复错误
end try
begin catch
select error_message() as error_message
select description as error_message from sys.sysmessages where error=error_number() and msglangid='2052'
end catch
结果如下
error_message
---------------------------------------------
違反 PRIMARY KEY 條件約束 'PK_table1'。無法在物件 'dbo.table1' 中插入重複的索引鍵。重複的索引鍵值為 (2)。
error_message
---------------------------------------------
违反了 %1! 约束 '%2!'。不能在对象 '%3!' 中插入重复键。重复的键值为 %4!。
-->得到2个相似字符串,请楼主自行文本处理成所要的结果.