我有两个表格:
CREATE TABLE users
(
id int PRIMARY KEY IDENTITY,
firstname varchar(30),
lastname varchar(30),
age int
)
CREATE TABLE rejectedUsers
(
id int PRIMARY KEY IDENTITY,
firstname nvarchar,
lastname nvarchar,
age nvarchar
)
触发因素:
CREATE TRIGGER checkNumeric
ON users
INSTEAD OF INSERT
AS
INSERT INTO users SELECT firstname, lastname, age FROM inserted WHERE ISNUMERIC(age) = 1;
INSERT INTO rejectedUsers SELECT firstname, lastname, age FROM inserted WHERE ISNUMERIC(age) = 0;
-- goes fine
INSERT INTO users
VALUES
( Vlad , P , 21)
-- fails
INSERT INTO users
VALUES
( Chuck , Norris , abc )
第二篇发言给我留下了一个错误:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value abc to data type int.
我期望触发器在<条码>上插入什么错误?