在Sql Server中创建一个触发器,提示before不是可以识别的触发器,怎么解决?
CREATETRIGGERtr1ON[dbo].[车辆]BEFOREDELETEforeachrowASbeginifexists(select*from车次where车...
CREATE TRIGGER tr1 ON [dbo].[车辆]
BEFORE DELETE
for each row
AS
begin
if exists(select * from 车次 where 车辆编号=(select 车辆编号 from deleted))
begin
delete from 车次 where 车辆编号=(select 车辆编号 from deleted)
end
end 展开
BEFORE DELETE
for each row
AS
begin
if exists(select * from 车次 where 车辆编号=(select 车辆编号 from deleted))
begin
delete from 车次 where 车辆编号=(select 车辆编号 from deleted)
end
end 展开
2个回答
展开全部
标准的创建触发器语言里面没有before,只有for
SQL触发器语法
语法
CREATE TRIGGER trigger_name
ON { table | view }
[ WITH ENCRYPTION ]
{
{ { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ DELETE ] [ UPDATE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS
[ { IF UPDATE ( column )
[ { AND | OR } UPDATE ( column ) ]
[ ...n ]
| IF ( COLUMNS_UPDATED ( ) updated_bitmask )
column_bitmask [ ...n ]
} ]
sql_statement [ ...n ]
}
}
SQL触发器语法
语法
CREATE TRIGGER trigger_name
ON { table | view }
[ WITH ENCRYPTION ]
{
{ { FOR | AFTER | INSTEAD OF } { [ INSERT ] [ DELETE ] [ UPDATE ] }
[ WITH APPEND ]
[ NOT FOR REPLICATION ]
AS
[ { IF UPDATE ( column )
[ { AND | OR } UPDATE ( column ) ]
[ ...n ]
| IF ( COLUMNS_UPDATED ( ) updated_bitmask )
column_bitmask [ ...n ]
} ]
sql_statement [ ...n ]
}
}
追问
可是我要实现在删除之前先把其他表中的相关记录删除
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询