程序笔记   发布时间:2022-07-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了sql server 特殊sql大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
SELEct t.type,t.name 表名 from sysobjects t where t.type in ('U','v' ,'TR') and t.name like '%%';SELEct t.type,t.name 表名,f.name 列名 from sysobjects t, sysColumns f where t.id = f.id and t.type in ('U','v' ,'TR');SELEct t.type,t.name 表名,f.name 列名 from sysobjects t, sysColumns f where t.id = f.id and t.type in ('U','v' ,'TR')  and t.name = '';SELEct t.type,t.name 表名,f.name 列名 from sysobjects t, sysColumns f where t.id = f.id and t.type in ('U','v' ,'TR')  and t.name like '%%';SELEct t.type,t.name 表名,f.name 列名 from sysobjects t, sysColumns f where t.id = f.id and t.type in ('U','v' ,'TR')  and f.name = '';SELEct t.type,t.name 表名,f.name 列名 from sysobjects t, sysColumns f where t.id = f.id and t.type in ('U','v' ,'TR')  and f.name like '%%';SELEct name from sysobjects where type = 'v' --全部视图SELEct name from sysobjects where type = 'v' and subString(name,1,3)<>'sys' --用户建立的视图
-- 查询最后一分钟执行的sql语SELECT TOP 100  Qs.last_execution_time AS '执行时间',  qs.creation_time as '首次执行时间',  ST.text AS '执行的sql语句',  Qs.execution_count AS '执行次数',  Qs.@R_861_1@R_673_11226@6@l_elapsed_time AS '耗时',  Qs.@R_861_1@R_673_11226@6@l_logical_reads AS '逻辑读取次数',  Qs.@R_861_1@R_673_11226@6@l_logical_writes AS '逻辑写入次数',  Qs.@R_861_1@R_673_11226@6@l_physical_reads AS '物理读取次数',  qp.query_plan as 'xml'-- Qs.*FROM   sys.dm_exec_query_stats QS  CROSS APPLY      sys.dm_exec_sql_text(Qs.sql_handlE) ST  CROSS APPLY      sys.dm_exec_query_plan(qs.plan_handlE) qpWHERE  Qs.last_execution_time betweeN dateadd(minute,-1,getdate()) AND dateadd(minute,+2,getdate())ORDER BY  last_execution_time asc,creation_time asc, Qs.@R_861_1@R_673_11226@6@l_elapsed_time DESc;
-- 全库查找指定的字符串declare @Str nvarchar(maX), @tablename varchar(50), @colname varchar(50), @rowCount intSELEct a.name tablename, b.name Colname, 0 as IsFound into #t1from sysobjects a join sysColumns b on a.id=b.id join systypes c on b.xtype=c.xtypewhere a.[type]='U' and c.name in ('varchar') --这里是设置字段的类型,以缩小范围declare _c1 cursor for SELEct Colname, tablename from #t1open _c1fetch next from _c1 into @colName, @tablenamewhile @@FETCH_STATUS=0 begin  --print @Str  SELEct @Str='SELEct @rowCount=count(1) from ['+@tablename+'] where ['+@colName+'] = ''要查找的内容''' --这里是要查找的内容  exec sp_executesql @Str, N'@rowCount int output', @rowCount output  if @rowCount>0 update #t1 set IsFound=1 where ColName=@colName and tablename=@tablename  fetch next from _c1 into @colName, @tablenameendclose _c1deallocate _c1SELEct * from #t1 where IsFound=1drop table #t1;

大佬总结

以上是大佬教程为你收集整理的sql server 特殊sql全部内容,希望文章能够帮你解决sql server 特殊sql所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。