微前端架构如何改变企业的开发模式与效率提升
244
2023-12-07
这篇文章主要介绍了数据库中tmstamp monitor的示例代码,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
USE [DBCenter] GO /****** Object: StoredProcedure [dba].[GetRowDiff] Script Date: 2017/5/8 13:06:50 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO alter procedure [dba].[GetRowDiff] as declare @databse_name varchar(15), @schema_name varchar(10), @table_name varchar(100), @max_tmstamp_2bigint, @row_count_2 bigint, @max_tmstamp_1 bigint, @row_count_1bigint, @datetime datetime, @sql varchar(8000), @record_time_1 varchar(19), @record_time_2varchar(19) SET NOCOUNT on set @sql= set @datetime =getdate() truncate tableDBCenter..viewTMstamp_diffdeclare mycursor cursor for selectaa.databse_name,aa.[schema_name],aa.table_name,aa.max_tmstampas max_tmstamp_2,aa.row_count as row_count_2,bb.max_tmstamp as max_tmstamp_1,bb.row_count asrow_count_1,convert(varchar(19),aa.record_time,120) as record_time_2,convert(varchar(19),bb.record_time,120) as record_time_1 from ( selecta.databse_name,a.[schema_name],a.table_name,a.max_tmstamp,a.row_count,a.record_timefrom [DBCenter].[dbo].[viewMaxTMtamp] a with (nolock) where convert(varchar(10),a.record_time,120)++convert(varchar(2),a.record_time,114) = convert(varchar(10),dateadd(hh,0,getdate()),120)++convert(varchar(2),dateadd(hh,0,getdate()),114) ) as aa join ( selectb.databse_name,b.[schema_name],b.table_name,b.max_tmstamp,b.row_count,b.record_timefrom [DBCenter].[dbo].[viewMaxTMtamp] b with (nolock) where convert(varchar(10),b.record_time,120)++convert(varchar(2),b.record_time,114) = convert(varchar(10),getdate(),120)++convert(varchar(2),dateadd(hh,-1,getdate()),114) )as bb on aa.databse_name=bb.databse_name and aa.[schema_name]=bb.[schema_name] andaa.table_name=bb.table_name--打开游标 open mycursor --从游标里取出数据赋值到我们刚才声明的2个变量中 fetch next from mycursor into@databse_name,@schema_name,@table_name,@max_tmstamp_2,@row_count_2,@max_tmstamp_1,@row_count_1,@record_time_2,@record_time_1--判断游标的状态 -- 0 fetch语句成功 ---1 fetch语句失败或此行不在结果集中 ---2 被提取的行不存在 while (@@fetch_status=0) begin set @sql=insert into DBCenter..viewTMstamp_diff([db_name],[schema_name],[table_name],[row_count_diff],[tmstmp_row_count_diff],[tmstmp_diff],[record_time_2],[record_time_1],[date_time]) select++@databse_name++,++@schema_name++,++@table_name++,+cast((@row_count_2-@row_count_1)as varchar(100))+as row_count_diff,count(1) as tmstmp_row_count_diff , +cast((@max_tmstamp_2-@max_tmstamp_1)as varchar(100))+as tmstmp_diff,++convert(varchar(19),@record_time_2,120)++,++convert(varchar(19),@record_time_1,120)++,++convert(varchar(19),getdate(),120)++ from +@databse_name+.+@schema_name+.+@table_name+with (nolock) where cast(TMSTAMP as bigint) >=+cast(@max_tmstamp_1 as varchar(100))+ and cast(TMSTAMP as bigint)<+cast(@max_tmstamp_2 as varchar(100)) --print @sql EXEC (@sql) set @sql=insert into DBCenter..viewTMstamp_diff_his([db_name],[schema_name],[table_name],[row_count_diff],[tmstmp_row_count_diff],[tmstmp_diff],[record_time_2],[record_time_1],[date_time]) select++@databse_name++,++@schema_name++,++@table_name++,+cast((@row_count_2-@row_count_1)as varchar(100))+as row_count_diff,count(1) as tmstmp_row_count_diff , +cast((@max_tmstamp_2-@max_tmstamp_1)as varchar(100))+ as tmstmp_diff,++convert(varchar(19),@record_time_2,120)++,++convert(varchar(19),@record_time_1,120)++,++convert(varchar(19),getdate(),120)++ from +@databse_name+.+@schema_name+.+@table_name+with (nolock) where cast(TMSTAMP as bigint) >=+cast(@max_tmstamp_1 as varchar(100))+ and cast(TMSTAMP as bigint)<+cast(@max_tmstamp_2 as varchar(100)) --print @sql EXEC (@sql) fetch next from mycursor into@databse_name,@schema_name,@table_name,@max_tmstamp_2,@row_count_2,@max_tmstamp_1,@row_count_1,@record_time_2,@record_time_1end --关闭游标 close mycursor --撤销游标 DEALLOCATE mycursor SET NOCOUNT off GOUSE [datayesdb] GO /****** Object: StoredProcedure [dba].[GetMaxTMstmp] Script Date: 2017/5/8 14:07:04 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE procedure [dba].[GetMaxTMstmp] @database varchar(20), @schema varchar(20), @tbnamenvarchar(100), @datetime datetime as declare @Max_TMstmp bigint declare @sql nvarchar(4000) declare@sql2nvarchar(4000) declare @i int=0 DECLARE @startDate1 DATE; DECLARE @startDate DATETIME; DECLARE@endDate DATETIME ;SET NOCOUNT on SET @startDate1=GETDATE();SELECT @startDate=DATEADD(DAY,-0,@startDate1); SET@endDate=DATEADD(d,+1,CONVERT(DATETIME,@startDate1)); --SELECT @startDate startDate,@endDate endDate; --set @tbname=bond --print @tbname begin --print @tbname set @sql2=select @i=count(1) from sys.columns col with (nolock) join sys.tables tbl with (nolock) on col.object_id=tbl.object_id where tbl.name=+ +@tbname++ and col.name in (++TMSTAMP++,++UPDATE_TIME++) and tbl.type=++U++ and tbl.schema_id =schema_id(++@schema++) --print @sql2 exec sp_executesql @sql2 ,N@i int out ,@i out --print @i if isnull(@i,0)=2 begin set @sql= insert into [DBCenter].[dbo].[viewMaxTMtamp] ([databse_name],[schema_name],[table_name],[min_tmstamp],[max_tmstamp],[row_count],[min_update_time],[max_update_time],[record_time]) select ++@database++,++@schema++,++@tbname++ , isnull(cast(min(TMSTAMP) as bigint),0)+, isnull(cast(max(TMSTAMP) as bigint),0)+,count(1)+, min(UPDATE_TIME)+, max(UPDATE_TIME),+ +cast (@datetime as varchar(20))++ from +@database+.+@schema+.+@tbname + with (nolock) --print @sql EXEC (@sql) end end SET NOCOUNT off ------------------------------------------------------------------------------------------------------------------------- GOUSE [datayesdb] GO /****** Object: StoredProcedure [dba].[GetMaxTMstmp_job] Script Date: 2017/5/8 14:07:45 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE procedure [dba].[GetMaxTMstmp_job] as declare @database varchar(20), @schema varchar(20), @tblnamevarchar(100), @datetime datetime SET NOCOUNT on set @datetime=GETDATE() set @database=datayesdb declare mycursor cursor for select schema_name(schema_id) [schema],name from sys.tables with (nolock) where type=U order by [schema],name --打开游标 open mycursor --从游标里取出数据赋值到我们刚才声明的2个变量中 fetch next from mycursor into @schema,@tblname --判断游标的状态 -- 0 fetch语句成功 ---1 fetch语句失败或此行不在结果集中 ---2 被提取的行不存在 while (@@fetch_status=0) begin --print @tblname exec dba.GetMaxTMstmp @database,@schema,@tblname,@datetime fetch next from mycursor into @schema,@tblname end --关闭游标 close mycursor --撤销游标 DEALLOCATE mycursor SET NOCOUNT off GO感谢你能够认真阅读完这篇文章,希望小编分享的“数据库中tmstamp monitor的示例代码”这篇文章对大家有帮助,同时也希望大家多多支持,关注行业资讯频道,更多相关知识等着你来学习!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~