CREATE TRIGGER UPDATE_SPJ
ON SPJ
AFTER UPDATE
AS
INSERT INTO
HSPJ(SNO,PNO,JNO,QTY,USERNAME,MODIFYDATE)
SELECT SNO,PNO,JNO,QTY,CURRENT_USER,GETDATE()
FROM INSERTED
WHERE EXISTS(
SELECT *
FROM DELETED
WHERE INSERTED.SNO = DELETED.SNO AND
INSERTED.PNO = DELETED.PNO AND
INSERTED.JNO = DELETED.JNO
10 个解决方案
#1
after换instead of试试
#2
机子上没联机丛书,不行的话你先找找联机丛书
#3
就是报语法错误,换成instead of也不行
#4
联机丛书怎么用啊?小白刚学,没用过,我看的教材是《数据库系统概论》第四版,萨师煊的
#5
晕,那个是标准SQL,T-SQL不一定支持,算了,我开虚拟机看看吧。2012的联机丛书要独立下载
#6
语法:
-- SQL Server Syntax
Trigger on an INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)
CREATE TRIGGER [ schema_name . ]trigger_name
ON { table | view }
[ WITH <dml_trigger_option> [ ,...n ] ]
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
[ NOT FOR REPLICATION ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }
<dml_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]
<method_specifier> ::=
assembly_name.class_name.method_name
SQL Server 2012没有of的用法
#7
例子:不用of,直接after就可以了
USE AdventureWorks2012;
GO
IF OBJECT_ID ('Sales.reminder2','TR') IS NOT NULL
DROP TRIGGER Sales.reminder2;
GO
CREATE TRIGGER reminder2
ON Sales.Customer
AFTER INSERT, UPDATE, DELETE
AS
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'AdventureWorks2012 Administrator',
@recipients = 'danw@Adventure-Works.com',
@body = 'Don''t forget to print a report for the sales force.',
@subject = 'Reminder';
GO
#8
定义某一列update的触发器sql 2008及其以下版本的
则用if update(某字段)
sql 2012的还没用过哦,改天研究下
则用if update(某字段)
sql 2012的还没用过哦,改天研究下
#9
恩恩,if update不会用,在下面加个约束条件就行了,谢谢啦
#10
嗯,谢谢大神~~
#1
after换instead of试试
#2
机子上没联机丛书,不行的话你先找找联机丛书
#3
就是报语法错误,换成instead of也不行
#4
联机丛书怎么用啊?小白刚学,没用过,我看的教材是《数据库系统概论》第四版,萨师煊的
#5
晕,那个是标准SQL,T-SQL不一定支持,算了,我开虚拟机看看吧。2012的联机丛书要独立下载
#6
语法:
-- SQL Server Syntax
Trigger on an INSERT, UPDATE, or DELETE statement to a table or view (DML Trigger)
CREATE TRIGGER [ schema_name . ]trigger_name
ON { table | view }
[ WITH <dml_trigger_option> [ ,...n ] ]
{ FOR | AFTER | INSTEAD OF }
{ [ INSERT ] [ , ] [ UPDATE ] [ , ] [ DELETE ] }
[ NOT FOR REPLICATION ]
AS { sql_statement [ ; ] [ ,...n ] | EXTERNAL NAME <method specifier [ ; ] > }
<dml_trigger_option> ::=
[ ENCRYPTION ]
[ EXECUTE AS Clause ]
<method_specifier> ::=
assembly_name.class_name.method_name
SQL Server 2012没有of的用法
#7
例子:不用of,直接after就可以了
USE AdventureWorks2012;
GO
IF OBJECT_ID ('Sales.reminder2','TR') IS NOT NULL
DROP TRIGGER Sales.reminder2;
GO
CREATE TRIGGER reminder2
ON Sales.Customer
AFTER INSERT, UPDATE, DELETE
AS
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'AdventureWorks2012 Administrator',
@recipients = 'danw@Adventure-Works.com',
@body = 'Don''t forget to print a report for the sales force.',
@subject = 'Reminder';
GO
#8
定义某一列update的触发器sql 2008及其以下版本的
则用if update(某字段)
sql 2012的还没用过哦,改天研究下
则用if update(某字段)
sql 2012的还没用过哦,改天研究下
#9
恩恩,if update不会用,在下面加个约束条件就行了,谢谢啦
#10
嗯,谢谢大神~~