<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sys.databases on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/sys.databases/</link><description>Recent content in Sys.databases on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Mon, 13 Apr 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/tags/sys.databases/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server Backup History: Duration and Size Report</title><link>https://www.sqlserver70.com/post/sql-server-backup-history-duration-size-report/</link><pubDate>Mon, 13 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-backup-history-duration-size-report/</guid><description>
&lt;h2 id="query-backup-duration-and-file-size-from-sql-server-history"&gt;Query Backup Duration and File Size from SQL Server History&lt;/h2&gt;
&lt;p&gt;This script queries SQL Server's msdb backup history to report the backup type, start and finish time, duration in minutes, and file size in both megabytes and gigabytes for every backup across all user databases on the server.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Knowing that a backup completed is only part of the picture. DBAs also need to understand how long each backup took and how large the resulting files are. A backup that used to finish in ten minutes now taking an hour is worth investigating. A backup file that is half its usual size may indicate a failed or partial operation. This script, adapted from the DBA-Scripts collection by Bulent Gucuk, joins &lt;code&gt;sys.databases&lt;/code&gt; with &lt;code&gt;msdb.dbo.backupset&lt;/code&gt; and &lt;code&gt;msdb.dbo.backupmediafamily&lt;/code&gt; to surface both duration and size in a single result set. Running it regularly gives you a baseline so that anomalies are easy to spot.&lt;/p&gt;</description></item><item><title>SQL Server Backup Status Report: All Databases</title><link>https://www.sqlserver70.com/post/sql-server-backup-status-report-last-backup-all-databases/</link><pubDate>Fri, 10 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-backup-status-report-last-backup-all-databases/</guid><description>
&lt;h2 id="check-sql-server-backup-age-across-all-databases"&gt;Check SQL Server Backup Age Across All Databases&lt;/h2&gt;
&lt;p&gt;This script queries the SQL Server backup history catalog to report the most recent full, differential, and transaction log backup for every database, including how many hours and minutes ago each backup completed.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Database backups are your last line of defense against data loss. Knowing exactly when each database was last backed up — and how old that backup is right now — is a fundamental DBA responsibility. This script, originally written by Tim Ford, joins &lt;code&gt;master.sys.databases&lt;/code&gt; with the msdb backup history tables to produce a single report covering all backup types for all databases. It shows the backup finish time, the physical backup file path, and elapsed time in both hours and minutes, making it straightforward to spot any database that has missed a scheduled backup.&lt;/p&gt;</description></item><item><title>SQL Server Point-in-Time Restore with STOPAT</title><link>https://www.sqlserver70.com/post/sql-server-point-in-time-restore-script-stopat/</link><pubDate>Sun, 05 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-point-in-time-restore-script-stopat/</guid><description>
&lt;h2 id="recover-a-sql-server-database-to-a-specific-point-in-time"&gt;Recover a SQL Server Database to a Specific Point in Time&lt;/h2&gt;
&lt;p&gt;SQL Server's &lt;code&gt;RESTORE LOG ... WITH STOPAT&lt;/code&gt; lets you roll a database back to any exact moment covered by your backup chain. This guide walks through querying backup history in &lt;code&gt;msdb&lt;/code&gt;, executing the restore sequence, and verifying the result.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Data loss incidents — accidental deletes, bad deployments, runaway updates — rarely happen at a convenient backup boundary. Point-in-time restore solves this by replaying transaction logs only up to a target timestamp, leaving the database in a consistent state as of that moment.&lt;/p&gt;</description></item><item><title>SQL Server Database Size Report for All Databases</title><link>https://www.sqlserver70.com/post/sql-server-database-size-report-all-databases/</link><pubDate>Thu, 02 Apr 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-database-size-report-all-databases/</guid><description>
&lt;h2 id="report-database-size-in-mb-and-gb-for-all-sql-server-databases"&gt;Report Database Size in MB and GB for All SQL Server Databases&lt;/h2&gt;
&lt;p&gt;This script queries &lt;code&gt;sys.master_files&lt;/code&gt; and &lt;code&gt;sys.databases&lt;/code&gt; to report the total allocated size in megabytes and gigabytes for every user database on the SQL Server instance, sorted by largest database first.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;Knowing how large each database is — and tracking how that size changes over time — is a core part of SQL Server capacity planning. Running out of disk space is one of the most disruptive events a DBA can face: it halts log backups, prevents transactions from committing, and can take databases offline. This script, adapted from the DBA-Scripts collection by Bulent Gucuk, reads allocated file sizes from &lt;code&gt;sys.master_files&lt;/code&gt; and joins to &lt;code&gt;sys.databases&lt;/code&gt; to produce a single server-wide size report. It runs from the master database, requires no cross-database queries, and takes milliseconds to execute — making it safe to run at any time, including during a production incident.&lt;/p&gt;</description></item><item><title>SQL Server Blocking Detection: Find Blocked Sessions</title><link>https://www.sqlserver70.com/post/sql-server-blocking-detection-find-blocked-sessions/</link><pubDate>Sun, 01 Mar 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-blocking-detection-find-blocked-sessions/</guid><description>
&lt;p&gt;Blocking in SQL Server occurs when one session holds a lock that another session needs, causing the second session to wait. This T-SQL script queries the dynamic management views to show all currently blocked sessions, the blocking session, wait type, wait duration, and the SQL text involved.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;When users report slow queries or application timeouts, blocking is a common cause. SQL Server does not alert you to blocking by default — you must query the DMVs to see what is happening in real time.&lt;/p&gt;</description></item><item><title>Generate DBCC SHOWCONTIG Commands for All SQL Server Tables</title><link>https://www.sqlserver70.com/post/generate-dbcc-showcontig-commands-for-all-user-tables-in-sql-server/</link><pubDate>Fri, 01 Aug 2025 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/generate-dbcc-showcontig-commands-for-all-user-tables-in-sql-server/</guid><description>
&lt;h2 id="generate-dbcc-showcontig-commands-for-all-user-tables-in-sql-server"&gt;Generate DBCC SHOWCONTIG Commands for All User Tables in SQL Server&lt;/h2&gt;
&lt;p&gt;Database administrators frequently need to monitor table and index fragmentation to maintain optimal database performance. This SQL Server script provides an efficient way to generate DBCC SHOWCONTIG commands for all user tables in your database automatically.
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;/p&gt;
&lt;h2 id="purpose"&gt;Purpose&lt;/h2&gt;
&lt;p&gt;The primary purpose of this script is to dynamically generate DBCC SHOWCONTIG commands for every user table in a SQL Server database. This eliminates the need to manually write individual commands for each table, saving time and ensuring comprehensive fragmentation analysis across all tables.&lt;/p&gt;</description></item></channel></rss>