Scripts

Technical Article

SQL Server Automated Backup & SAN Replication Solution

Script created by Syed Fahar Abbas. A Comprehensive Batch Script to: Verify/Request Administrator privileges and create a stable script copy. Grant NT AUTHORITY\SYSTEM database privileges and perform full SQL Server backup. Detect, or automatically download and silently install, WinRAR for compression. Compress the raw backup (.bak) into a high-compression RAR archive (.rar) and cleanup. Authenticate […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

(1)

You rated this post out of 5. Change rating

2026-09-29

9 reads

Technical Article

Server-Level Table sizes

This script creates a stored procedure that returns the following table size metrics in kilobytes, megabytes, and gigabytes for all tables in user-created databases (database ID > 4): Reserved space Used space Unused space Index size Data size

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2026-09-14

48 reads

Technical Article

Stored Procedures for Server-Level Object and Column Search

This script creates two stored procedures: One searches for the names of all user-created objects at the server level across all user-created databases (database ID > 4) based on a specified search expression. The other searches for column names in all user-created tables and views across all user-created databases (database ID > 4) based on […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2026-09-09

44 reads

Technical Article

Server-Level Row Counts for Tables and Views

This script creates a table that will store the row counts of non-system tables and views across all user-created databases (database ID > 4) on the server, as well as a stored procedure that refreshes the row counts by recalculating them. The script uses the database ServerInfo to store the table and stored procedure. Replace […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2026-09-04

65 reads

Technical Article

Demo Tracking Dropped Objects

This script demonstrates step by step how to implement a dropped objects tracking flow. Important limitation to consider: The stored state of a dropped object is based on the most recent available snapshot and not necessarily on the state of the object immediately before it was dropped. The accuracy of the stored information depends on […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2026-08-31

45 reads

Technical Article

Randomly Selecting Columns and Rows from a Table or View

The following script creates a procedure that returns a specified number of random columns and rows from a specified table or view. The number of columns and rows is determined by the @NumberOfColumns and @Rows parameters. The @RandomColumnOrder parameter specifies whether the selected columns are returned in random order or sorted by their ordinal position […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2026-08-31

55 reads

Technical Article

Column Data Types

This scripts creates a view containing data type information for columns in user-defined tables and views. It provides an overview of the data types in use and can help identify opportunities for data type optimization and standardization. The data types are formatted as they appear in Object Explorer in SSMS. For example, sysname is displayed […]

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

You rated this post out of 5. Change rating

2026-08-25

62 reads

Blogs

10 Decisions to Make Before You Create A Fabric Workspace

By

Creating a Fabric workspace takes about 30 seconds. Restructuring workspaces after people have built...

Flyway Tips: Object History

By

It’s a small change, but a handy one. Flyway Desktop (FWD) now includes the...

Car Update September 2026

By

Software is hard. While I love our Lucid Gravity, I realize that they are...

Read the latest Blogs

Forums

Adding new column with DEFAULT II

By Thomas Franz

Comments posted to this topic are about the item Adding new column with DEFAULT...

Advanced Deployment Scenarios: Stairway to Reliable Database Deployments Level 7

By Massimo Preitano

Comments posted to this topic are about the item Advanced Deployment Scenarios: Stairway to...

You Need a DBA Pipeline

By Steve Jones - SSC Editor

Comments posted to this topic are about the item You Need a DBA Pipeline

Visit the forum

Question of the Day

Adding new column with DEFAULT II

Which number did the two COUNT(*) return:

DROP TABLE IF EXISTS #tmp
CREATE TABLE #tmp (id INT NOT NULL)

INSERT INTO #tmp (id) 
SELECT gs.value
  FROM GENERATE_SERIES(1, 5) AS gs

ALTER TABLE #tmp ADD my_value INT NOT NULL CONSTRAINT df_tmp_my_value DEFAULT 1

SELECT COUNT(*)  FROM #tmp AS t WHERE my_value = 1

ALTER TABLE #tmp DROP CONSTRAINT df_tmp_my_value

ALTER TABLE #tmp ADD CONSTRAINT df_tmp_my_value DEFAULT 2 FOR my_value

SELECT COUNT(*)  FROM #tmp AS t WHERE my_value = 1

See possible answers