• sqlserver常用命令收集(持续更新)


    1.查看数据库日志使用率

    DBCC SQLPERF(LOGSPACE)
    

    2.查看表结构

    sp_help tablename
    
    sp_columns tablename
    

    3.查询中添加行号

    select ROW_NUMBER() over (order by main_id), main_id from MC_MF_JXYDJY
    

    4.查询一个数据库中某个字段的位置

        declare @cloumns varchar(40)
    declare @tablename varchar(40)
    declare @str varchar(40)
    declare @counts int
    declare @sql nvarchar(2000)
    declare MyCursor Cursor For 
    Select a.name as Columns, b.name as TableName from syscolumns a,sysobjects b,systypes c 
    where a.id = b.id
    and b.type = 'U' 
    and a.xtype=c.xtype
    and c.name like '%char%'
    set @str='张三'
    Open MyCursor
    Fetch next From MyCursor Into @cloumns,@tablename
    While(@@Fetch_Status = 0)
    Begin
     set @sql='select  @tmp_counts=count(*) from ' +@tablename+ ' where ' +@cloumns+' = ''' +@str+ ''''
    execute sp_executesql  @sql,N'@tmp_counts int out',@counts out
     if @counts>0
     begin
     print '表名为:'+@tablename+',字段名为'+@cloumns
     end
    Fetch next From MyCursor Into @cloumns,@tablename
    End
    Close MyCursor
    Deallocate MyCursor
    

    5.查询一个最近的执行语句

    SELECT 
    *
    FROM 
        sys.dm_exec_query_stats QS
    CROSS APPLY 
        sys.dm_exec_sql_text(QS.sql_handle) ST
    

      

    **********初心不改,方得始终。
  • 相关阅读:
    mysql 时间戳 转 时间
    VSCode搭建VUE 开发环境
    虚拟通信
    JavaScript 获取客户端计算机硬件及系统信息
    Thinkphp关联模型BELONGS_TO
    docker部署rancher踩坑篇
    青龙面板 脚本 依赖库下载安装
    Linux 随记
    Tekton DAG代码
    手写Spring valar
  • 原文地址:https://www.cnblogs.com/salv/p/10120471.html
Copyright © 2020-2023  润新知