zoukankan      html  css  js  c++  java
  • SQL 常用脚本

    SELECT o.name AS tableName,c.name AS colName,k.keyno AS sort
    FROM sysindexes i
    JOIN sysindexkeys k ON i.id = k.id AND i.indid = k.indid
    JOIN sysobjects o ON i.id = o.id
    JOIN syscolumns c ON i.id=c.id AND k.colid = c.colid
    WHERE EXISTS( SELECT 1 FROM sysobjects WHERE name = i.name) 
    AND o.name=@tableName--表名称
    ORDER BY o.name,k.colid
    

      

    查找所有存储过程包含了哪些表,函数

    select * from sys.all_sql_modules where definition like '%[NAME]%'

    查找作业步骤里执行了哪些存储过程

    select * from   [msdb].[dbo].[sysjobsteps] where command like '%recmsg_orderresult%' 

    查找所有作业信息

    select * from   [msdb].[dbo].[sysjobs] where job_id = ''

    --查看数据库后台进程

    SELECT session_Id, 
                    --ecid, 
                    --sp.dbid,
                    --DB_NAME(sp.dbid) as DB_NM, 
                    --nt_username,
                    er.status,
                    wait_type,
                    SUBSTRING (qt.text, er.statement_start_offset/2,
                                        (CASE WHEN er.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.text)) * 2
                                                    ELSE er.statement_end_offset END - er.statement_start_offset)/2) as CurrentSQL,
                    qt.text,
                    --program_name,
                    --Hostname,
                    start_time,
                    DATEDIFF ( millisecond,start_time, GETDATE() ) AS  execTime
    FROM sys.dm_exec_requests er
    INNER JOIN sys.sysprocesses sp ON er.session_id = sp.spid
    CROSS APPLY sys.dm_exec_sql_text(er.sql_handle)as qt
    WHERE session_Id > 50             
    AND session_Id NOT IN (@@SPID) 
    --and sp.dbid=7
    ORDER BY DATEDIFF ( millisecond,start_time, GETDATE() ) desc

     -- 获取主键排序

    SELECT o.name AS tableName,c.name AS colName,k.keyno AS sort
    FROM sysindexes i
    JOIN sysindexkeys k ON i.id = k.id AND i.indid = k.indid
    JOIN sysobjects o ON i.id = o.id
    JOIN syscolumns c ON i.id=c.id AND k.colid = c.colid
    WHERE EXISTS( SELECT 1 FROM sysobjects WHERE name = i.name) 
    AND o.name=@tableName--表名称
    ORDER BY o.name,k.colid

     -- 获取数据库中所有表名及数据条数

    select  b.name as tablename ,  
            c.row_count as datacount  
    from    sys.indexes a ,  
            sys.objects b ,  
            sys.dm_db_partition_stats c  
    where   a.[object_id] = b.[object_id]  
            AND b.[object_id] = c.[object_id]  
            AND a.index_id = c.index_id  
            AND a.index_id < 2  
            AND b.is_ms_shipped = 0   
    order by b.name
            
    

      

  • 相关阅读:
    Git第一次新建项目添加ssh key
    第一次将本地项目同步到git服务器
    python实现差分隐私Laplace机制
    利用皮尔逊相关系数找出与目标最相关的特征(Python实现)
    corrcoef函数python_用Numpy计算Python中的Pearson相关系数
    Python Numpy库 numpy.corrcoef()函数讲解
    皮尔森相关系数(Pearson correlation coefficient)
    Python三种方法计算皮尔逊相关系数(Pearson correlation coefficient)
    特征选择 (feature_selection)
    基于模型的特征选择详解
  • 原文地址:https://www.cnblogs.com/nonkicat/p/4178684.html
Copyright © 2011-2022 走看看