日期:2014-05-16 浏览次数:20714 次
--建测试表
IF OBJECT_ID('test') IS NOT NULL
BEGIN
DROP TABLE test
END
GO
CREATE TABLE [dbo].[test](
[id] [bigint] PRIMARY KEY IDENTITY(1,1) NOT NULL,
[name] [nvarchar](200),
[desc] [nvarchar](50),
) ON [PRIMARY]
GO
--测试触发器
IF EXISTS (SELECT * FROM sys.triggers WHERE object_id = OBJECT_ID(N'[dbo].[trig_Test_Insert2]'))
BEGIN
DROP TRIGGER [dbo].[trig_Test_Insert2]
END
GO
CREATE TRIGGER [trig_Test_Insert2]
ON [dbo].[test]
FOR INSERT
AS
BEGIN
SELECT 1/0
IF @@ERROR<>0
raiserror('执行出错',16,1)
END
GO
--测试语句
INSERT INTO test ([name],[desc]) VALUES ( 'name1', 'desc1' )
SELECT * FROM test t