Tag Archives: DBA Scripts

SQL Script to find the database & their files details on a SQL Server

SQL Script to find database details Sometimes we need a SQL Script which can give the below information about the databases created on a SQL Server for house keeping purpose: -1) Database Name 2) Database ID 3) Database Files name … Continue reading

Posted in DBA | Tagged , | 31 Comments

SQL Script: – How to find the database restoring history of SQL Server databases

SQL Script to find database restoring history Sometime we need to find out the history of database restoration to get the answers of following questions: -1) Do we need to restore the database again as there is a possibility that it … Continue reading

Posted in DBA, SQL Database Restoration | Tagged , | 28 Comments

SQL Script: – How to find the last access date of a database

SQL Script to find database last access date Sometime we create databases on Test/ Development database servers for temporary uses for short duration and  forgot to delete them after the work got completed. As a part of house keeping activity, … Continue reading

Posted in DBA | Tagged , | 35 Comments

SQL Script to find all the triggers defined on a database or on a single table

SQL Script to find triggers in SQL Database Sometime we need to find all the triggers defined on the database. So in this case, we can use the below SQL Query:-SELECT tbl.name as [Table Name] , trig.name as [Trigger Name] … Continue reading

Posted in SQL Advanced, SQL Tips, SQL Triggers | Tagged , | 30 Comments

Script to find complete months between two given dates

Complete months between two given dates Below script will help in finding the complete months within the 2 given dates. In the below script we takes below dates as exampleStartdate =2015-07-05 Enddate =2016-01-06 /**********************Script Start**************************/ IF (object_id(‘tempdb..#month’) is not null) … Continue reading

Posted in Interview Questions, SQL Basic, SQL Server | Tagged , , | Leave a comment

Script to find the complete weeks within two given dates

Complete weeks within two given dates Sometimes we need to find out the complete weeks within two given dates. Below script will help in finding the complete weeks within 2 given dates. In this script, I have used below dates … Continue reading

Posted in Interview Questions, SQL Basic, SQL Server, SQL Tips | Tagged , | 21 Comments

SQL Script to find the missing indexes

Script to find the missing indexes Performance tuning in SQL is important exercise and index creation is an important part of it. Sometimes base on the frequent SQL queries, we need to create some indexes or missing indexes which are enhance the … Continue reading

Posted in DBA, SQL Advanced, SQL Indexes, SQL Server | Tagged , | 29 Comments

SQL Script to find the list of all the jobs failed yesterday

One of the important task of any DBA is to find out all the jobs which are failed yesterday. Below SQL Script can be used to find out all the jobs which are failed yesterday. SELECT DISTINCT CAST(CONVERT(datetime,CAST(run_date AS char(8)),101) … Continue reading

Posted in DBA, SQL Advanced, SQL Server | Tagged , | Leave a comment

SQL Script to search stored procedures containing a given text

Sometimes we need to find out how many stored procedures contains a given text. Below SQL query can be used to find out the list of all the stored procedures which contains a  particular given text as input. SELECT OBJECT_NAME(object_id), … Continue reading

Posted in DBA, SQL Advanced, SQL Server | Tagged , | 32 Comments

SQL Script to find the tables created from a given date

Below is the SQL query which can be used to find out the tables which are created or modified on or from a given date. SELECT         [name] as Tablename        ,create_date       … Continue reading

Posted in DBA, SQL Advanced, SQL Server | Tagged , | 29 Comments