监控数据库表变化
2014-02-14 15:54
495 查看
CREATE PROCEDURE usr_run_1 AS
declare @name varchar(50)
declare @id int
declare @count int
declare @sql nvarchar(255)
select id,name into #tmp20140215 from sysobjects where type='u' order by name
select @count=count(*) from #tmp20140215
print cast (@count as varchar(10))
while exists(select * from #tmp20140215)
begin
select @id=id,@name=name from #tmp20140215
-- usr_run_2 @name, @count output
set @sql='use ais20140121142916 select @count=count(*) from ' +@name
exec master.dbo.sp_executesql @sql,N'@count int output',@count output
insert into a99 (tab_name,first_run) values (@name,@count)
delete from #tmp20140215 where id=@id
end
select @count=count(*) from a99
print cast (@count as varchar(10))
CREATE PROCEDURE usr_run_2 AS
declare @name varchar(50)
declare @id int
declare @count int
declare @sql nvarchar(255)
select id,name into #tmp201402151 from sysobjects where type='u' order by name
while exists(select * from #tmp201402151)
begin
select @id=id,@name=name from #tmp201402151
-- usr_run_2 @name, @count output
set @sql='use ais20140121142916 select @count=count(*) from ' +@name
exec master.dbo.sp_executesql @sql,N'@count int output',@count output
-- insert into a99 (tab_name,first_run) values (@name,@count)
update a99 set second_run=@count where tab_name=@name
delete from #tmp201402151 where id=@id
end
数据名叫 ais201401211429,创建了一个表a99 字段 tab_name,first_run,second_run
先运行 usr_run_1,然后添加一条记录,再运行usr_run_2
就\在a99中就可以看到先后的不同
declare @name varchar(50)
declare @id int
declare @count int
declare @sql nvarchar(255)
select id,name into #tmp20140215 from sysobjects where type='u' order by name
select @count=count(*) from #tmp20140215
print cast (@count as varchar(10))
while exists(select * from #tmp20140215)
begin
select @id=id,@name=name from #tmp20140215
-- usr_run_2 @name, @count output
set @sql='use ais20140121142916 select @count=count(*) from ' +@name
exec master.dbo.sp_executesql @sql,N'@count int output',@count output
insert into a99 (tab_name,first_run) values (@name,@count)
delete from #tmp20140215 where id=@id
end
select @count=count(*) from a99
print cast (@count as varchar(10))
CREATE PROCEDURE usr_run_2 AS
declare @name varchar(50)
declare @id int
declare @count int
declare @sql nvarchar(255)
select id,name into #tmp201402151 from sysobjects where type='u' order by name
while exists(select * from #tmp201402151)
begin
select @id=id,@name=name from #tmp201402151
-- usr_run_2 @name, @count output
set @sql='use ais20140121142916 select @count=count(*) from ' +@name
exec master.dbo.sp_executesql @sql,N'@count int output',@count output
-- insert into a99 (tab_name,first_run) values (@name,@count)
update a99 set second_run=@count where tab_name=@name
delete from #tmp201402151 where id=@id
end
数据名叫 ais201401211429,创建了一个表a99 字段 tab_name,first_run,second_run
先运行 usr_run_1,然后添加一条记录,再运行usr_run_2
就\在a99中就可以看到先后的不同
相关文章推荐
- mysql database manual(mysql数据库手册)
- 什么是DAO Database Access Object
- 在数据库‘master’中拒绝CREATE DATABASE权限问题的解决方法
- Sample script that deletes a SQL Server database
- 用MyEclipse配置DataBase Explorer(图示)
- 11. Laravel 4 结构生成器 Schema
- 【转】mysql ERROR 1049 (42000): Unknown database '******' ”错误处理办法
- 未处理sqlException解决办法
- Oracle 数据库管理员的任务
- suse yast another process is accessing the package database
- 跳过rman坏块进行数据恢复
- RHEL 6.3 LAMP环境配置 ncurses 出错及解决
- 关闭RAC、srvctl命令
- Oracle 重做日志恢复(二)
- 数据库连接池DBCP 、c3p0配置参数说明
- 如何迁移Xenapp或xendesktop数据库 Migration citrix Database
- 数据库异常关闭后无法启动问题处理一例
- 怎样实现对一个表的增、删、改和查询功能
- 备份系统数据
- how to get the space size of some tables in one database?