![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
::----------SQL触发器-------------------------------------------------
1.删除
CREATE TRIGGER [Delete_TopAlexa] ON [dbo].[tb_WebSite]
FOR DELETE
AS
BEGIN TRANSACTION
delete from tb_alexa where websiteid=(select websiteid from deleted)
delete from tb_top100 where websiteid=(select websiteid from deleted)
IF (@@ERROR <> 0) -- 如果有错误
BEGIN
ROLLBACK TRANSACTION -- 回滚
END
COMMIT TRANSACTION -- 提交事务
2.更新
create trigger Test_OK
on ok
for update
as
if update(name)
begin
update sname set sname.s_name=ok.name from ok,sname
where sname.n_id=ok.n_id
end
::----------SQLite触发器-------------------------------------------------
1.删除
Create Trigger MAIN.[UserOK_DeleteOK] AFTER DELETE On [UserOK] FOR EACH ROW
begin
delete from userbak where uid=old.uid ;
end;
2.更新
Create Trigger MAIN.[UserOK_Update] AFTER UPDATE On [UserOK] FOR EACH ROW
begin
update userbak set username=new.username
where userbak.uid=old.uid ;
end;
1.删除
CREATE TRIGGER [Delete_TopAlexa] ON [dbo].[tb_WebSite]
FOR DELETE
AS
BEGIN TRANSACTION
delete from tb_alexa where websiteid=(select websiteid from deleted)
delete from tb_top100 where websiteid=(select websiteid from deleted)
IF (@@ERROR <> 0) -- 如果有错误
BEGIN
ROLLBACK TRANSACTION -- 回滚
END
COMMIT TRANSACTION -- 提交事务
2.更新
create trigger Test_OK
on ok
for update
as
if update(name)
begin
update sname set sname.s_name=ok.name from ok,sname
where sname.n_id=ok.n_id
end
::----------SQLite触发器-------------------------------------------------
1.删除
Create Trigger MAIN.[UserOK_DeleteOK] AFTER DELETE On [UserOK] FOR EACH ROW
begin
delete from userbak where uid=old.uid ;
end;
2.更新
Create Trigger MAIN.[UserOK_Update] AFTER UPDATE On [UserOK] FOR EACH ROW
begin
update userbak set username=new.username
where userbak.uid=old.uid ;
end;
Sqlite 清空表中所有数据 并重置自增长数据
delete from 表名;
select * from sqlite_sequence;
找到上面的 表名
update sqlite_sequence set seq=0 where name='表名';
select * from sqlite_sequence;
找到上面的 表名
update sqlite_sequence set seq=0 where name='表名';
以上UPDATE() 函数可用于确定 INSERT 或 UPDATE 语句是否影响表中的特定列。无论何时为列赋值,该函数都将返回 TRUE。
由于使用 DELETE 语句无法删除列中的特定值,因此不能将 IF UPDATE() 子句应用于 DELETE 语句。 |
此外,COLUMNS_UPDATED 函数也可用于检查 INSERT 或 UPDATE 语句更新了表中的哪些列。此函数使用整数位掩码指定要测试的列。有关详细信息,请参阅 CREATE TRIGGER。