摘要:触发器语句中使用了两种特殊的表:deleted 表和 inserted 表. create trigger updateDeleteTimeon userfor updateasbegin update user set UpdateTime=(getdate()) from user inner join inserted on user.UID=Inserted.UIDend 上面的例子是在执行更新操作的时候同时更新,一下修改时间.关键在于Inserted表触发器语句中使用了两种特殊
--存储过程,循环create or replace procedure delTables(ename t_emp.ename%TYPE)AScon number;i NUMBER := 1;tablename USER_TABLES.TABLE_NAME%TYPE;BEGIN select count(TABLE_NAME) into con from USER_TABLES where last_analyzed > to_date('2014/1/17 00:00:00','yyyy/m
游标 在游标逐行处理过程中,当需要处理的记录数较大,而且游标处理位于数据库事务内时,速度非常慢. -- 声明变量 DECLARE @Id AS Int -- 声明游标 DECLARE C_Id CURSOR FAST_FORWARD READ_ONLY FOR SELECT b.Id FROM dbo.Books b; -- 打开游标 OPEN C_Id; -- 取第一条记录 FETCH NEXT FROM C_Id INTO @Id; BEGIN --逻辑处理 SELECT * FROM db
先吐槽一下,由于公司要为新客户部署一个全新的系统,然而公司并没有空库,所以只能把正在线上运行的数据库给备份,然后清空相关数据 下面分享一下我在做清空数据库时写的一个批量清空数据表的方法 思路:查询出该库下的所有表 根据表名(系统相关数据表取名都是有规律的)筛选出需要清空的表 下面,上代码 USE [DataBase] GO ) DECLARE @count int DECLARE contact_cursor CURSOR FOR select name from sysobjects wher
use databaseName declare @tblname char(100) declare @sql char(5000) declare table_cursor cursor for select name from sysobjects where name like 'tb_card[_]%' and name<>'Tb_card_regist' and name<>'Tb_card_item' and name<>'Tb_card_discr
--触发器学习-------------------------------------------------------------------------------after 触发器---------------------------------------------------------------------------------1 insert 触发器IF EXISTS(SELECT * FROM sys.objects WHERE name='tgr_tablename_
在日常工作中,在SqlServer2008R2中,需要向一张表上加上触发器,监控插入.更新.删除. --一个触发器内三种INSERT,UPDATE,DELETE状态 IF exists(select 1 from inserted) and not exists(select 1 from deleted) begin --INSERT end IF exists(select 1 from inserted) and exists(select 1 from deleted) begin --
create trigger updateDeleteTime on user for update as begin update user set UpdateTime=(getdate()) from user inner join inserted on user.UID=Inserted.UID end 上面的例子是在执行更新操作的时候同时更新,一下修改时间.关键在于Inserted表触发器语句中使用了两种特殊的表:deleted 表和 inserted 表.Deleted 表用于
create trigger updateDeleteTime on user for update as begin update user set UpdateTime=(getdate()) from user inner join inserted on user.UID=Inserted.UID end 上面的例子是在执行更新操作的时候同时更新,一下修改时间.关键在于Inserted表触发器语句中使用了两种特殊的表:deleted 表和 inserted 表.Deleted 表用于存储
[cursor]游标:用于循环表行数据,类似指针 格式如下: declare tempIndex cursor for (select * from table) --定义游标 open tempIndex --打开游标 fetch next from tempIndex into @x --抓取下一行数据给变量 --0表示抓取成功,1表示抓取失败,2表示不存在抓取行 begin --sql 语句 end close tempIndex --关闭游标 deallocate tempIndex -