Skip to content
Writing

Articles

289 articles, snippets and musings on programming, databases, networking and more.

289 articles

Borland 5.02

Last version of the Borland C++ IDE with bundled tools which supports 16-bit development.

Jul 30, 2025cppideretro

Article Archive

Archive of all old article downloads.

Apr 12, 2025

Joshua Chisum

Josh Chisum was one of my earliest friends, gracious software tester and a source of constant moral support.

Aug 15, 202013legendmember

A Brief Introduction to Secure Scripting

A Brief Introduction to Secure Scripting with PL-SQL

Jun 7, 2017

Non-unique Primary Keys?

Are primary keys always unique? If not, when?

Aug 28, 2015sql-server

Disk Benchmarking with SQLIO

Benchmark your server's storage with various block-sizes and centralize the results foe easy analysis.

Jan 16, 2015iosql-server

Dial-up Sounds Explained

Ever wondered what all that noise was when establishing a dial-up connection?

Feb 5, 2014legacymusing

SQL Server Virtual File Stats

Easily view the cumulative I/O stats for each SQL Server database file.

Aug 17, 2013snippetsql-server

Bringing RESTful Services to C++ Developers

Bringing RESTful Services to C++ Developers

Aug 12, 2013cppmusing

Simple Debugging with AllocConsole

AllocConsole is a debuggers friend - now made easier with STD-I/O redirection.

Feb 20, 2013

Java is a Horrible Language

Linus Torvalds, the creator of my second favorate operating system expresses discontent with java - and I couldn't agree more.

Feb 17, 2013javamusing

Enable or Disable Schema Replication

A straight forward approach to enabling of disabling the automatic replication of schema changes in transactional replication.

Feb 10, 2013replicationsnippetsql-server

Page Splits per-Second Over Time

A script to get you on the easy road to page-split baselining.

Feb 9, 2013snippetsql-server

Alter the Fill Factor on all GUID Columns

Easily decrease the fill factors on all of those uniqueidentifier/GUID columns.

Feb 9, 2013snippetsql-server

Finding Duplicate SQL Statistics

A quick and efficient view to find duplicate statistics on your SQL Server tables.

Feb 9, 2013snippetsql-server

Finding Duplicate SQL Indexes

A quick and efficient view to find duplicate indexes on your SQL Server tables.

Feb 9, 2013snippetsql-server

Get Table Row Counts

A script to quickly retrieve the count of rows from all tables in a database.

Feb 9, 2013snippetsql-server

Read File as Table

Allows you to easily select from a file on the file system as if it were a table.

Feb 9, 2013snippetsql-server

Split Array

SplitArray is a powerful table SQL function which splits delimited values into a row-set.

Feb 9, 2013snippetsql-server

Row List

Returns a table with a given number of rows.

Feb 9, 2013snippetsql-server

Get Days Of Month

Returns a table with one row per day of a given year and month.

Feb 9, 2013snippetsql-server

Get First and Last day of Month

Two simple functions to get the first and last day of a month.

Feb 9, 2013snippetsql-server

Format Currency

Easy currency formatting of numbers in SQL Server using a scalar function.

Feb 9, 2013snippetsql-server

Format Number and Decimal Value

Easy formatting of numbers in SQL Server using a scalar function.

Feb 9, 2013snippetsql-server

String and Numeric Padding

SQL functions used to left and right pad a values with 0s (or some other value),

Feb 9, 2013snippetsql-server

Delete Unused Agent Schedules

Ever stepped back and looked at the enourmous barrage of unused SQL Agent Schedules? Clean them up!

Feb 8, 2013snippetsql-agentsql-server

Proper Name Casing in SQL Server

Need to format a name for a form? Well, this isn't perfect by any means, but it's a start.

Feb 8, 2013snippetsql-server

Exploited antique code

Exploited antique code warning, not for the faint of heart!!

Feb 8, 2013academiacpp

Sockets in Win32

Sockets: The foundation of a computer's social life.

Feb 8, 2013cppsocket

Password Cracking

Generic password cracking with a password list for ethical internal security probing.

Feb 8, 2013hashing

Microsoft's ListView, What is it good for?

Microsoft's ListView... What is it good for?! Well, I've got a few ideas...

Feb 8, 2013cppsnippet

It's not volatile, this is critical

For far too long I have listened to the likes of those who believe that the volatile modifier is the end-all answer to multi-threaded development.

Feb 8, 2013cppthreading

Identifying Page Splits in SQL Server

SQL and SQL only: Identifying Page Splits in a SQL Server Database

Feb 8, 2013sql-server

64-bit development, it's no Fad

64-bit development. It's no fad.

Feb 8, 2013cppx64

Going Native : Day 1 Keynote - Bjarne Stroustrup: C++11 Style

Bjarne Stroustrup speaks words of gold at the Going Native Conference.

Feb 8, 2013cppmusing

Josh Patterson

My name is Josh Patterson, original founder of NetworkDLS

Jan 25, 2013member

Lcc-Win32

A tribute to Jacob Navia and my favorite compiler: LCC-Win32

Feb 19, 2012cppmusing

IO DMVs

A collection of queries covering the IO DMVs: per-file IO stats, pending IOs, IO by drive letter and index space usage.

Dec 10, 2010snippetsql-server

Rename a SQL Server Instance

A short script showing how to rename a SQL Server instance's registered name and verify it.

Dec 1, 2010snippetsql-server

Page Life Expectancy Health

A script that compares Page Life Expectancy against a computed target and reports buffer pool health as a percentage.

Nov 29, 2010snippetsql-server

Split Words

A table valued function that splits text into words on spaces and punctuation, remembering each word's position.

Nov 19, 2010snippetsql-server

vDomainUser View

A view that splits the current user name into Domain and Username columns.

Nov 14, 2010snippetsql-server

Current Activity DMVs

A collection of queries covering the current-activity DMVs: sessions, connections, requests, waiting tasks and blocked processes.

Nov 13, 2010snippetsql-server

Change Replication Username and Password

A script generator that produces the T-SQL needed to change the agent credentials for log reader, snapshot and distribution agents across a publication.

Oct 31, 2010replicationsnippetsql-server

Script All Primary Keys

A script that generates create or drop statements for every primary key in the database, preserving clustering and column direction.

Oct 19, 2010snippetsql-server

Recommend Decimal Field Sizes

A script that scans actual decimal values and recommends the tightest fitting data type for each column, with ALTER scripts.

Oct 15, 2010snippetsql-server

How Long Since Restart

A one-line query that returns the SQL Server instance's last restart time.

Sep 20, 2010snippetsql-server

Database Users Without Connect Permission

A query that lists every database principal lacking the CONNECT permission and generates a grant script for each.

Sep 14, 2010snippetsql-server

Parse Proc Call Traces

A view that parses stored procedure names out of RPC:Completed rows in a trace table.

Aug 30, 2010snippetsql-server

Date Array

A table valued function that returns one row per day between a start and end date.

Aug 24, 2010snippetsql-server

Last Table Select

A query that reports the last seek, scan or lookup date for every user table using index usage statistics.

Aug 2, 2010snippetsql-server

Running Jobs

A query that lists all SQL Agent jobs currently executing with their elapsed time.

Jul 12, 2010snippetsql-agentsql-server

CPU Usage by SPID Over Time

A query that measures CPU consumption per SPID over a 30-second window with full SQL text.

Jul 6, 2010performancesnippetsql-server

Recommend String Field Sizes

A script that scans actual string lengths and recommends right-sized varchar/nvarchar columns with ALTER scripts.

May 18, 2010snippetsql-server

QuickTrace

A one-shot server trace that runs for a fixed duration, captures the standard tuning events, reads the results back and deletes the file.

Apr 20, 2010snippetsql-server

Toggle Foreign Keys on an Object

A stored procedure that enables or disables all foreign key constraints on a table, optionally including referencing tables.

Apr 16, 2010snippetsql-server

View Snapshot Isolation Disk Usage

A query that reports snapshot isolation version store disk usage per database relative to tempdb.

Mar 16, 2010snippetsql-server

Fix Orphaned Users

How to repair a single orphaned database user with sp_change_users_login Auto_Fix.

Mar 5, 2010snippetsql-server

Count CRLF Pairs in a String

A scalar function that counts how many Windows-style carriage return / line feed (CRLF) pairs exist inside a string.

Mar 4, 2010snippetsql-server

Indexing DMVs

A collection of queries covering the indexing DMVs: operational stats, usage stats, fragmentation and missing index recommendations.

Feb 7, 2010snippetsql-server

Force Drop Publisher from Distributor

A last-resort script for removing a publisher and its distribution database from the distributor when normal unconfiguration fails.

Jan 19, 2010replicationsnippetsql-server

Resource Governor Starter Setup

A Resource Governor starter setup with workload groups and a classifier function routing by login and application.

Jan 19, 2010snippetsql-server

sp_help_revlogin for SQL Server 2000

The original SQL Server 2000 version of sp_help_revlogin using sysxlogins and sp_addlogin.

Jan 9, 2010snippetsql-server

CPU DMVs

A collection of queries covering the CPU-related DMVs: schedulers, signal vs resource waits and the processes currently using CPU.

Jan 7, 2010snippetsql-server

Free Space in All Databases

A script that reports free space in gigabytes for every file in every online database on the server.

Jan 4, 2010snippetsql-server

SQL Agent Reader Permissions

The complete grant script for giving a user read-only SQL Server Agent visibility.

Jan 2, 2010snippetsql-agentsql-server

Test Compile All Procedures

A script that test-compiles every procedure, function, trigger and view in the database and reports the ones that fail.

Dec 26, 2009snippetsql-server

App Query Duration

A query that reports how long each of a specific application's queries has been executing.

Dec 24, 2009performancesnippetsql-server

Replication Monitor Alerts Job

The SQL Agent job definition that runs SendErrorAlerts every ten minutes to surface replication errors.

Dec 8, 2009replicationsnippetsql-server

Skip Snapshot Process

A trick for forcing the distribution agent through a snapshot cycle without actually delivering any data.

Nov 20, 2009replicationsnippetsql-server

View All Users Permissions on All Databases

A cursor-driven script that audits every permission in every database and shows which roles inherit them.

Oct 21, 2009snippetsql-server

Show Index Statistics

The DBCC SHOW_STATISTICS variants for inspecting index statistics headers, density vectors and histograms.

Oct 17, 2009snippetsql-server

Top 10 Queries by Total CPU Time

A query that lists the top ten queries by total CPU time with per-execution averages.

Oct 2, 2009snippetsql-server

Guid Search

A stored procedure that finds every table and column containing a given GUID across the whole database.

Sep 22, 2009snippetsql-server

Enable or Disable All Foreign Keys on a Table

Two statements that disable or enable all foreign key constraints on a table at once.

Sep 13, 2009snippetsql-server

Get Login Info

A stored procedure that reports the host, domain and user name of the current session.

Aug 24, 2009snippetsql-server

Change Database Growth Rate

A script that sets a consistent file growth rate on every data and log file in every online database.

Aug 17, 2009snippetsql-server

Enable Change Tracking on Database and Table

The two ALTER statements that turn on change tracking for a database and for an individual table.

Aug 8, 2009snippetsql-server

Password Cracker

A brute-force and dictionary SQL login password cracker that reports blank, username-as-password and cracked accounts.

Jun 20, 2009snippetsql-server

Trace Filter Ids

A reference table of every SQL Server trace filter column id with its name and description.

Jun 16, 2009snippetsql-server

Performance Data Collection Viewer

A stored procedure that reports weighted notable query statistics from the Maintenance Data Warehouse over a time range.

Jun 6, 2009snippetsql-server

Replace a GUID Everywhere

A stored procedure that replaces one GUID with another across every uniqueidentifier column in a database.

Jun 4, 2009snippetsql-server

Agent Job Step Duration

A query that decodes SQL Agent job history durations into real datetimes and seconds for sorting and analysis.

May 26, 2009snippetsql-agentsql-server

Sample IO Performance

A script that samples virtual file I/O statistics over ten minutes and reports per-file throughput and latency.

May 19, 2009snippetsql-server

Poll SPID Performance

A script that polls a single SPID every second and breaks down its wait types, CPU and physical I/O until it sleeps.

Apr 30, 2009snippetsql-server

sp_help_revlogin

The classic stored procedure that generates CREATE LOGIN scripts for every login on a SQL Server instance.

Apr 25, 2009snippetsql-server

Missing Indexes

A query that reports missing index candidates with improvement measures and generated CREATE INDEX statements.

Mar 26, 2009snippetsql-server

Statistics With Columns View

Two views that expose every statistic's columns and flag duplicate statistics on the same column set.

Mar 17, 2009snippetsql-server

View Tables and Indexes with Compression

Queries that list every table and index partition with its data compression setting.

Mar 5, 2009snippetsql-server

Enable and Disable Schema Replication

Two sp_changepublication calls that turn DDL (schema change) replication on or off for a publication.

Feb 24, 2009replicationsnippetsql-server

View All Users Permissions

A CTE query that lists every effective permission in the current database, tracing role grants back to their members.

Feb 18, 2009snippetsql-server

Articles with Missing Filter Procedures

A diagnostic query that finds replicated articles whose row filter procedures have gone missing from the publisher database.

Feb 15, 2009replicationsnippetsql-server

View Transaction Isolation Levels

A query that lists every session with its current transaction isolation level.

Feb 8, 2009snippetsql-server

Currently Executing Requests

A query that reports full detail on every request currently executing, including the exact statement text.

Dec 12, 2008snippetsql-server

User Specific Schema

A script that gives a user their own schema with full rights inside it while denying them the dbo schema.

Dec 9, 2008snippetsql-server

GreaterOf Series

A family of four scalar functions that return the greatest of two, three, four, or five values.

Nov 23, 2008snippetsql-server

Update All Statistics with Fullscan

A script that forces a full-scan statistics update on every table regardless of the row modification counter.

Oct 14, 2008snippetsql-server

Read Commands from Distribution Database

How to use sp_browsereplcmds on the distribution database to inspect pending replication commands when diagnosing agent errors.

Oct 11, 2008replicationsnippetsql-server

Page Splits by Index

A per-database query that counts page splits per index from the transaction log.

Aug 20, 2008snippetsql-server

Refresh All Views

A stored procedure that refreshes every view in the database and reports only the real failures.

Aug 16, 2008snippetsql-server

Set Publication Defaults

A batch of sp_changepublication calls that reset a publication to native sync with anonymous and immediate sync disabled.

Aug 12, 2008replicationsnippetsql-server

fn_trace_gettable

How to read a .trc trace file back into a table, with and without event class names.

Jun 23, 2008snippetsql-server

Replication Monitor Database

The complete DDL for a ReplicationMonitor database that records replication throughput and errors over time.

Jun 11, 2008replicationsnippetsql-server

Space Used by Table Across a Database

A stored procedure that runs sp_spaceused against every table in a given database and returns one combined report.

Jun 5, 2008snippetsql-server

Virtual File Stats

Queries that report cumulative virtual file I/O statistics per file and per database.

Jun 2, 2008snippetsql-server

Get XML Inner Text

A scalar function that extracts the inner text of a named tag from a simple XML string using substring math.

Mar 18, 2008snippetsql-server

Query To CSV

A stored procedure that wraps any single-column query into one delimited, optionally padded, comma-separated string.

Mar 14, 2008snippetsql-server

View Orphaned Users on All Databases

A cursor-driven script that finds orphaned users in every database on the server with drop scripts.

Mar 13, 2008snippetsql-server

Get Table Column Info

A stored procedure that reports every constraint, computed column, view and index attached to a given table column.

Feb 8, 2008snippetsql-server

Reset Fill Factors

A script that resets fill factors on all indexes to a standard policy, with lower fill for GUID-based indexes.

Feb 2, 2008snippetsql-server

Long Running Queries

A query that finds long-running queries that are waiting, blocked or holding open transactions.

Jan 31, 2008snippetsql-server

Script All Database Foreign Keys

A script that generates drop and create statements for every foreign key in the database, optionally limited to one table.

Jan 30, 2008snippetsql-server

Drop Foreign Keys on a Column

A stored procedure that drops all foreign key constraints attached to a given table's column.

Jan 19, 2008snippetsql-server

Write Query Results to a File

Stored procedures that write a table or any query's results to a delimited text file from inside SQL Server.

Jan 9, 2008snippetsql-server

Database File Usage by Process

A query that reports tempdb space usage in GB per process, with login and command details.

Dec 23, 2007snippetsql-server

Running Processes

A query that lists all active processes on the server with their current SQL statement, waits and resource usage.

Dec 15, 2007snippetsql-server

Drop a Column's Default Constraint

A stored procedure that drops a column's default constraint without dropping the column.

Dec 8, 2007snippetsql-server

Users by Database

A script that finds which databases contain a given user by searching sysusers across the whole server.

Dec 4, 2007snippetsql-server

Disable Index Page Locks

A script that generates statements to disable page locks on every index in the database.

Nov 14, 2007snippetsql-server

DBCheck

A stored procedure that checks or repairs a database, handling single-user mode, options and UPDATEUSAGE for you.

Nov 12, 2007snippetsql-server

SQL Trace Event Summary

A query that counts how many rows of each event class a trace table contains.

Oct 26, 2007snippetsql-server

Enable or Fix Service Broker on msdb

A short script that enables or repairs Service Broker on the msdb database.

Oct 25, 2007snippetsql-server

Compiled Plans vs Plan Stubs

A query that compares the size and count of compiled plans versus plan stubs in the cache.

Oct 2, 2007snippetsql-server

Get All Server Index Fragmentation

A stored procedure that reports index fragmentation across every database on the server with ready-to-run rebuild statements.

Sep 25, 2007snippetsql-server

Enable Snapshot Isolation

The statements to enable snapshot isolation on a database and monitor active snapshot transactions.

Sep 6, 2007snippetsql-server

Top Waits

A query that reports the top waits making up 95% of total wait time, split into resource and signal time.

Aug 30, 2007snippetsql-server

Generate Database Restore Scripts

A script that generates RESTORE DATABASE ... MOVE statements for every online user database on the server.

Jul 28, 2007snippetsql-server

Enable CDC on All Tables

A script that generates the statements to enable change data capture on every table in the current database.

Jul 23, 2007snippetsql-server

Audit Password Complexity

A script that audits SQL login passwords against a wordlist using PWDCOMPARE to find weak or dictionary-based passwords.

Jul 20, 2007securitysnippetsql-server

Shrink All Log Files

A stored procedure that truncates and shrinks the log file in every online database on the server.

Jul 17, 2007snippetsql-server

Delete Rows Containing a GUID

A stored procedure that finds and deletes every row containing a given GUID across all uniqueidentifier columns in a database.

Jun 16, 2007snippetsql-server

Ragged Sort

A scalar function that zero-pads mixed numeric and text values so they sort in natural order.

Jun 1, 2007snippetsql-server

Compare and Fix Replicated Data

A script generator that produces a batch of tablediff and sqlcmd commands to compare and repair every replicated table on a subscriber.

May 26, 2007replicationsnippetsql-server

Remove a Specific Plan from the Cache

A query that lists all cached plans with their handles and text so you can evict a specific one with DBCC FREEPROCCACHE.

May 7, 2007snippetsql-server

Drop Article and Re-add without Reinitializing

A step-by-step procedure for dropping a single article from a publication and re-adding it without forcing a full reinitialization.

May 6, 2007replicationsnippetsql-server

Print NVarChar(Max)

A stored procedure that prints nvarchar(max) values in line-break-aware 4000-character chunks.

Apr 23, 2007snippetsql-server

Password Cracker v2

A set-based SQL login password cracker that matches a word list against SHA-1 hashes with MAXDOP control.

Apr 20, 2007snippetsql-server

View All Permissions

A query that lists every permission granted in the current database with the principal, class and object.

Apr 12, 2007snippetsql-server

Database Count, Allocated and Used Space

A script that reports the count, allocated space and used space in gigabytes across all databases on the server.

Mar 4, 2007snippetsql-server

Simple Dead Lock Trace

A server trace that captures only deadlock graph events for a fixed window.

Feb 18, 2007snippetsql-server

Format DateTime

A scalar function that formats a datetime into any of about twenty named formats, including a UNIX timestamp.

Feb 13, 2007snippetsql-server

Rename Subscriber Database

A seven-step checklist for renaming a subscriber database and updating every replication table that references it.

Feb 4, 2007replicationsnippetsql-server

Week Days In Month

A scalar function that returns the number of business days (Monday to Friday) in the month of a given date.

Jan 25, 2007snippetsql-server

SQL Trace Event Class Names

A reference table of every SQL Server trace event class id and its name.

Jan 15, 2007snippetsql-server

Move Databases to New Storage

A script that generates ALTER DATABASE MODIFY FILE statements to move every database's files to new locations.

Jan 13, 2007snippetsql-server

Sort a Delimited String

A scalar function that sorts the pieces of a delimited string and rejoins them with the same delimiter.

Dec 24, 2006snippetsql-server

Execution DMVs

A collection of queries covering the execution DMVs: query stats, cached plans and plan attributes for finding and analyzing queries.

Dec 15, 2006snippetsql-server

View All SysAdmins

A query that lists every sysadmin login on the server with its type and dates.

Dec 8, 2006snippetsql-server

Record Log Reader Commands

A stored procedure that scrapes log reader agent history from every distributor database and records hourly command throughput for reporting.

Nov 19, 2006replicationsnippetsql-server

Get All Index Fragmentation Levels

A query that reports the fragmentation percentage and page count of every index in the current database.

Nov 17, 2006snippetsql-server

Remove SQL User

A stored procedure that generates the complete drop script for a user across every database: objects, schemas, users and login.

Nov 11, 2006snippetsql-server

Job History View

A view over sysjobhistory that converts the packed run date/time/duration integers into readable start and end times.

Nov 7, 2006snippetsql-server

Queries Taking Longer Than One Hour of CPU

A query that finds all queries whose cumulative CPU worker time exceeds one hour, with plan handles for eviction.

Nov 7, 2006snippetsql-server

Abandon Pending Log Reads

A three-line recovery script that resets the log reader and flushes replication when pending reads must be abandoned.

Nov 2, 2006replicationsnippetsql-server

Overall DMVs

A collection of queries covering the overall health DMVs: wait statistics, performance counters, system info and memory state.

Nov 1, 2006snippetsql-server

Create Partition Check Constraints

A script that generates IN-list check constraints on low-cardinality columns to support table partitioning.

Oct 24, 2006snippetsql-server

Clear Cache Entries for a Resource Pool

How to clear all cached plans associated with a specific Resource Governor resource pool.

Sep 26, 2006snippetsql-server

Drop All Non-Primary-Key Indexes

A script that generates DROP INDEX statements for every non-primary-key index in the database.

Sep 19, 2006snippetsql-server

Change Tracking Version to Date Time

A query that converts change tracking commit versions from sys.dm_tran_commit_table into local time.

Sep 6, 2006snippetsql-server

Table Size (Rows and Bytes)

A query that reports row counts and data size in GB for every user table in the current database.

Aug 30, 2006snippetsql-server

Add or Remove NOT FOR REPLICATION on All Identity Columns

A script that adds or removes the NOT FOR REPLICATION attribute on every identity column in the current database.

Jul 19, 2006replicationsnippetsql-server

SQL Agent Admin Permissions

The complete grant script for giving a user full SQL Server Agent administration rights.

Jul 2, 2006snippetsql-agentsql-server

Skip Individual Log Reader Transaction

A detailed runbook for isolating and skipping a single bad transaction that has halted the log reader agent.

Jun 16, 2006replicationsnippetsql-server

View Orphaned Users

A query that finds orphaned users in the current database and generates a drop script for each.

Jun 15, 2006snippetsql-server

Grant Server State

The single grant statement that lets a login view server performance counters and DMVs.

Jun 6, 2006snippetsql-server

Format Decimal Value

A scalar function that formats a decimal value with thousands separators and an exact number of decimal places.

Jun 3, 2006snippetsql-server

Memory DMVs

A collection of queries covering the memory DMVs: buffer usage by database and by object, plus Buffer Manager performance counters.

May 31, 2006snippetsql-server

Script Database Logins and Roles

Two queries that generate CREATE USER and sp_addrolemember scripts for every user and role membership in a database.

May 21, 2006snippetsql-server

Suggest Index Column Order

A stored procedure that suggests index column order based on measured distinct value counts.

May 11, 2006snippetsql-server

Move TempDB

A short script showing how to move the tempdb data and log files to a new location.

Apr 1, 2006snippetsql-server

Discover and Modify SQL Traces

How to list every running server trace and stop, start or delete one by id.

Mar 19, 2006snippetsql-server

Change All Databases to Simple Recovery

A script that switches every online database on the server to the SIMPLE recovery model.

Mar 13, 2006snippetsql-server

User Password Age

A query that lists every enabled SQL login whose password was last changed more than 90 days ago.

Feb 23, 2006snippetsql-server

Top 10 Longest-Running Queries

A query that lists the ten longest-running queries currently executing with their statement text.

Feb 19, 2006snippetsql-server

Using Change Tracking

A worked example of polling CHANGETABLE(CHANGES) with an anchor version to pull incremental changes.

Feb 4, 2006snippetsql-server

Search For Dependencies

A stored procedure that finds which SQL modules reference a given string in their definitions.

Jan 20, 2006snippetsql-server

Schema Map

A script that maps every table and column in the database with types, keys, foreign keys and extended property comments.

Jan 18, 2006snippetsql-server

Blocked and Blocking Processes

A comprehensive report of all blocked and blocking processes with wait details and full SQL text.

Jan 16, 2006snippetsql-server

Objects and Filegroups

A query that maps every index to its table, filegroup and physical file.

Jan 8, 2006snippetsql-server

Get the Nth Token from a Delimited String

A scalar function that returns the Nth token from a delimited string using a recursive CTE.

Dec 22, 2005parserssnippetsql-server

Simple Performance Tuner Trace

A fully annotated server trace template capturing the five standard tuning events with a complete commented filter library.

Dec 21, 2005snippetsql-server

Change All Database Owners to SA

A cursor-driven script that reassigns the owner of every user database on the server to sa.

Dec 5, 2005snippetsql-server

Resource User Roles DDL Trigger

A server-wide DDL trigger that maintains a ResourceUserRoles table tracking every database role membership.

Dec 3, 2005snippetsql-server

Replication Monitor Undistributed Commands Job

The SQL Agent job definition that records undistributed replication commands every fifteen minutes.

Nov 24, 2005replicationsnippetsql-server

Split Time

A scalar function that returns the time portion of a datetime as a string.

Oct 1, 2005snippetsql-server

Order Tables by Foreign Key Dependencies

A recursive CTE query that orders all user tables by their foreign key dependencies, from referenced to referencing.

Sep 15, 2005snippetsql-server

Trigger Template with Identity Preservation

A trigger template that saves and restores @@IDENTITY around trigger logic.

Sep 8, 2005snippetsql-server

Drop Column and Its Default Constraint

A stored procedure that drops a column together with its default constraint, if one exists.

Sep 7, 2005snippetsql-server

Regenerate Service Master Key

How to force-regenerate the service master key to fix replication decryption errors after a restore.

Aug 19, 2005snippetsql-server

Transparent Database Encryption

The four-step TDE setup: master key, certificate, database encryption key and turning encryption on.

Aug 3, 2005snippetsql-server

Deadlock Generator

A self-contained script that simulates repeatable deadlocks on demand for testing recovery code.

Jun 19, 2005performancesnippetsql-server

Cell Level Encryption

A complete walkthrough of cell-level data encryption using a master key, certificate and AES-256 symmetric key.

Jun 19, 2005securitysnippetsql-server

Page Splits Per Second

A script that measures page splits per second over a configurable time window using performance counters.

Jun 9, 2005snippetsql-server

Sample System Processes Over Time

A continuous sampler that records per-session CPU, I/O and wait deltas over a configurable time window.

May 22, 2005snippetsql-server

Get Primary Key Columns (GPKC)

A stored procedure that builds a formatted list of a table's primary key columns with configurable format tokens and delimiters.

May 21, 2005snippetsql-server

Toggle Indexes on an Object

A stored procedure that disables or rebuilds all non-primary-key indexes on a table, with an exclusion list.

May 17, 2005snippetsql-server

Repair a Suspect Database

The step-by-step sequence for attempting to repair a database that has gone into the suspect state.

May 17, 2005snippetsql-server

Replication Monitor Record Commands Job

The SQL Agent job definition that runs the log reader and distribution command recording procedures every minute.

Mar 23, 2005replicationsnippetsql-server

Remap Users

A cursor script that regenerates and executes ALTER USER WITH LOGIN statements for every mapped user in a database.

Mar 21, 2005snippetsql-server

DimTime Dimension

A script that populates a DimTime dimension table with every second of a day for SSAS time intelligence.

Mar 1, 2005snippetsql-server

Reindex with Before and After Comparison

A stored procedure that defrags or rebuilds fragmented indexes and reports before/after scan density with timing.

Feb 28, 2005snippetsql-server

Create a Database Snapshot with All Files

A script that generates the complete CREATE DATABASE ... AS SNAPSHOT OF statement for the current database, including all data files.

Feb 21, 2005snippetsql-server

Metaphone Phonetic Function

A complete T-SQL implementation of the Metaphone phonetic algorithm for fuzzy name matching.

Jan 27, 2005snippetsql-server

Cached Pages and Size by Database

A query that reports the number of cached pages and buffer pool usage in GB for each database.

Jan 17, 2005performancesnippetsql-server

Database Compression Evaluator

A script that estimates data compression savings for every table and generates rebuild scripts for the worthwhile ones.

Jan 11, 2005snippetsql-server

Common Controls - Calendar

A dialog demo for the date and time picker common controls, with the full ICC_ flag reference.

Nov 24, 2000cppwin32

NTFS Alternate Streams

A C program that writes to and reads back an NTFS Alternate Data Stream using plain fopen with a file:stream name.

Oct 20, 2000cppfile-systemwin32

Recursive Directory Scan

A C++ function that recursively walks a directory tree with FindFirstFile/FindNextFile, printing every file it finds.

Sep 21, 2000cppfile-managementwin32

Win32 Version Dialog

A Win32 dialog that displays the current Windows version string, with a ShellAbout entry in the system menu.

Jul 21, 2000cppwin32

CheckBox Dialog

A Win32 dialog demo showing how to detect a checkbox click and read its state with IsDlgButtonChecked.

Jun 28, 2000cppwin32

FILE Open Read Write Seek

A C console program that copies a file two ways — character at a time with fscanf, then in 512-byte buffered chunks after seeking back to the start.

Jun 6, 2000cppfile-managementwin32

Get File Size

A minimal C program that opens a file with CreateFile and prints its size in bytes using GetFileSize.

Apr 20, 2000cppwin32

Send To Printer

A C program that shows the standard print dialog and sends a line of text to the chosen printer using GDI.

Mar 22, 2000cppgdiwin32

File Mapped Memory Allocator

A C++ class that implements a full page-based memory allocator (Alloc, CAlloc, ReAlloc, Free, FreeAll) on top of a file-backed memory-mapped region.

Mar 14, 2000cppmemorywin32

Named Pipe Client Server

A pair of minimal C console programs — a named-pipe server built with CreateNamedPipe and a client that opens it and writes a message.

Mar 13, 2000cppipcwin32

RadioButton Dialog

A Win32 dialog example showing how to read the state of radio buttons with IsDlgButtonChecked.

Mar 12, 2000controlscppwin32

Suspend Process

A C console utility that attaches to a process by PID with DebugActiveProcess, leaving it suspended until the debugger detaches.

Feb 18, 2000cppthreadingwin32

NT Fiber

A minimal C++ program that converts the main thread to a fiber, creates a second fiber, and switches between them.

Feb 15, 2000cppthreadingwin32

Memory Status

A C console program that prints system memory statistics — physical, page file, and virtual — using GlobalMemoryStatus.

Sep 16, 1999cppmemorywin32

Tree View Dialog

A Win32 dialog example that builds a TreeView with an image list, adds nested nodes, and sub-classes the control to add its own behavior.

Sep 4, 1999controlscppwin32

Shell Extension Context Menu

The IContextMenu implementation from the Project Epsilon shell extension — adding a menu item with a bitmap and launching the associated program on selection.

Aug 23, 1999cppwin32

Win32 Set Attributes

A C program that sets a file's attributes to archive plus read-only using SetFileAttributes.

Aug 12, 1999cppfile-managementwin32

Network Connect Get Disconnect

A C program that connects to a network share with WNetAddConnection, queries it with WNetGetConnection, and disconnects with WNetCancelConnection — each with full error reporting.

Jul 21, 1999cppnetworkingwin32

Common Controls - IP Address

A dialog demo for the IP address common control, loaded with ICC_INTERNET_CLASSES.

Jul 18, 1999cppwin32

Change Case

LCase, UCase and MCase string helpers built on strlwr/strupr with a rotating buffer of results.

Jul 7, 1999cppwin32

Basic Window

The smallest complete Win32 window program: register a class, create a window, run the message loop.

Jun 30, 1999cppwin32

Open File Dialog Helper

A C helper function that wraps GetOpenFileName with file-type filters, a default extension, and an initial directory.

Jun 21, 1999cppwin32

Animated Icon

A dialog demo that displays an animated cursor or icon loaded from a resource or file.

Mar 27, 1999cppwin32

Load DLL At Runtime

A minimal pair of programs — a DLL exporting two functions and a console app that loads it at runtime with LoadLibrary/GetProcAddress.

Feb 24, 1999cppwin32

Shell Extension Class Factory

The COM plumbing of a Win32 shell extension DLL — DllGetClassObject, the class factory, reference counting, and QueryInterface across all six shell extension interfaces.

Dec 17, 1998cppwin32

Windows UpTime

A C console program that reports system uptime in days, hours, minutes, and seconds from GetTickCount.

Nov 22, 1998cpputilitywin32

Memory Mapping Helpers

Helper functions and a server/client pair for creating, opening, and mapping named shared memory backed by a file.

Oct 29, 1998cppwin32

Replace String In String

A C function that replaces every occurrence of a substring with another substring, building the result into a caller-supplied buffer.

Oct 17, 1998cppstringwin32

Build Lookup Table

A function that fills a 65 by 256 byte substitution table from a single build value using XOR mixing.

Aug 31, 1998cppwin32

Search In String

A hand-rolled C substring search that returns the index of the first occurrence, written before reaching for strstr.

Aug 17, 1998cppstringwin32

List System Directories

Four small C functions that return the current, temp, Windows, and system directories, each using a static buffer ring to stay safe across repeated calls.

Aug 16, 1998controlscppwin32

Scroll Window Into View

A Win32 technique that animates a window sliding up into view from below the desktop edge, driven by a worker thread.

Jul 20, 1998cppwin32

Hash Table

A public-domain C hash table (by Jerry Coffin) with insert, lookup, delete, enumerate, and free operations, plus a driver that exercises the full lifecycle.

Jul 4, 1998cppdata-structureswin32

Affinity Priority Fiber

A console snippet that pins a process and thread to a specific CPU using affinity masks and ideal-processor calls.

Jun 15, 1998cppthreadingwin32

DiskType & Size

A snippet that reports a drive's type and its total, free and available space in megabytes.

Jun 13, 1998cppdisk-iowin32

StdIO Binary Round Trip

A C++ program that writes a DWORD to a file with ofstream and reads it back with ifstream — raw binary I/O through the standard streams.

Jun 7, 1998cppiowin32

AllocConsole

A snippet that attaches a console to a GUI process and redirects stdout into it.

May 5, 1998cppwin32

Volume Information

A C program that queries a drive's volume name, file system, and capability flags with GetVolumeInformation.

Apr 15, 1998cppdisk-iowin32

Create Thread

A console snippet that spawns a second thread with CreateThread and lets both threads print in parallel.

Apr 1, 1998cppthreadingwin32

Detect WinVersion

A console snippet that identifies the running Windows version from GetVersionEx and prints it with build number.

Jan 31, 1998cppwin32

Move Rename File

A one-line C program that renames a file on the desktop using MoveFile.

Jan 9, 1998cppfile-managementwin32

Win32 Power Utilities

Three tiny C utilities — shutdown, restart, and logoff — each a confirmation dialog followed by one call to ExitWindowsEx.

Jan 4, 1998cpputilitywin32

Modeless Dialog

A Win32 example of running a dialog non-modally with CreateDialog plus a message loop, instead of the blocking DialogBox call.

Dec 30, 1997cppwin32

Server Extension DllMain

A minimal DllMain skeleton for a server-side extension DLL, handling process and thread attach/detach with initialization hooks.

Oct 13, 1997cppwin32

Shell Extension Registry Helpers

A portable registry helper library — create, delete (including recursive via SHDeleteKey), and get/set string, DWORD, and binary values.

Oct 1, 1997cppwin32

Linear Sort Algorithm

A simple linear (bubble-style) sort for an array of C strings, with a pass function that reports how many swaps it made.

Sep 9, 1997algorithmscppwin32

Reverse String

A C function that reverses a string in place using the XOR swap trick.

Aug 10, 1997cppstringwin32

Signal Event

A pair of C programs demonstrating cross-process synchronization with a named event — one waits on it, the other finds and signals it.

Jul 13, 1997cppthreadingwin32

Ticking Dialog

A Win32 dialog that displays the system tick count updating as fast as the timer allows — a minimal high-frequency UI refresh example.

Jul 7, 1997controlscppwin32

App Template

A minimal Win32 dialog application skeleton with single-instance mutex and a spinning OpenGL logo about box.

May 24, 1997cppwin32

ListView Dialog

A Win32 dialog example that builds a ListView with columns, a small icon image list, ten rows of data, custom text color, and sorting.

Mar 22, 1997controlscppwin32

Tray Icon Wrapper

A complete C++ tray-icon wrapper — create, update, and destroy a Shell_NotifyIcon entry with a right-click menu and TaskbarCreated recovery.

Dec 21, 1996cppwin32

C++ Classes

A minimal example of declaring a C++ class with public members and using an instance of it.

Dec 20, 1996cppwin32

ASCII Control Characters

A header of named constants for every ASCII control character, with a test program that prints their values.

Dec 8, 1996cppwin32

CreateKey

A snippet that creates a new registry key under HKEY_CLASSES_ROOT with RegCreateKeyEx.

Nov 28, 1996cppwin32

DiskType

A console snippet that walks every drive letter and reports its type with GetDriveType.

Nov 1, 1996cppdisk-iowin32

Get Resource User Name

A small C program that uses WNetGetUser to retrieve the username associated with a mapped network drive, with full error reporting.

Oct 12, 1996cppnetworkingwin32

SHA2 Implementation

A complete, dependency-free C implementation of the FIPS 180-2 SHA-2 family — SHA-224, SHA-256, SHA-384, and SHA-512.

Sep 24, 1996cppcryptographyhashingwin32

Date-Time

A snippet that formats the current date and time with GetDateFormat and GetTimeFormat.

Aug 20, 1996cppwin32

Fixed Memory Allocator

A C++ class implementing a page-chained memory allocator (Alloc, CAlloc, ReAlloc, Free) over a single fixed-size virtual memory block.

Jul 14, 1996cppmemorywin32

Splash Screen

A minimal Win32 splash screen — a borderless dialog with a bitmap that stays up for five seconds driven by a timer.

Jun 7, 1996cppwin32

Replace Char In String

A C function that returns a new string with every occurrence of one character replaced by another.

May 24, 1996cppstringwin32

DLL Skeleton

A minimal C DLL with a set of exported system and string functions, plus a console test driver that calls every export.

Apr 2, 1996cppwin32

Registry Delete Key

A minimal C program that opens a registry key and deletes a subkey with RegDeleteKey.

Mar 31, 1996cppregistrywin32

Basic DeviceIO

A console snippet that opens a raw disk handle and issues an IOCTL_STORAGE_EJECT_MEDIA control code.

Mar 30, 1996cppdisk-iowin32

Kill Process

A C console utility that attaches to a running process by PID using DebugActiveProcess and terminates it.

Mar 15, 1996cppwin32

Win32 Get Attributes

A C program that prints every set file attribute for a given file using GetFileAttributesEx.

Feb 8, 1996cppfile-managementwin32

Make Delete Directory

A five-line C program that creates a directory with CreateDirectory, waits, and removes it again with RemoveDirectory.

Jan 2, 1996cppfile-managementwin32

ListBox Dialog

A Win32 dialog application demonstrating ListBox message handling — inserting and deleting items via LB_INSERTSTRING and LB_DELETESTRING.

Dec 23, 1995controlscppwin32

Time Display

A C function that formats the current local time as HH:MM:SS using time, localtime, and strftime.

Dec 15, 1995cpptimewin32

Delete File

A one-line file deletion using DeleteFile, with the CRT unlink alternative commented alongside.

Oct 5, 1995cppfile-managementwin32

Run As Service

A C helper that calls RegisterServiceProcess to make the current process count as a Windows service, resolved dynamically from kernel32.

Sep 4, 1995cppserviceswin32

Calendar Control

A standalone Win32 program that creates a month calendar common control in its own window.

Sep 1, 1995cppwin32

Extended SQL2K StoredProc

A complete extended stored procedure (XSP) for SQL Server 2000 that takes a row count and returns that many rows with a greeting message.

Jul 20, 1995cppwin32

CheckPort Library

Two exported functions that test whether a TCP or UDP port on a host is in use.

Jul 2, 1995cppwin32

AVI Control

A dialog demo that plays an AVI file inside a window using the common controls Animate class.

May 21, 1995cppwin32

Load Cursor

A Win32 dialog example showing how to load cursors from system resources, compiled resources, and an .ani file on disk, then apply them with SetClassLong.

May 14, 1995cppwin32

Simple Dialog

The minimal Win32 dialog procedure — set title and icon, wire up an edit box and static text, run a one-second timer.

Apr 29, 1995controlscppwin32

Network Connect Get Disconnect v2

The WNetAddConnection2 variant of the network-drive example, using a NETRESOURCE structure to map a share with full error reporting.

Apr 20, 1995cppnetworkingwin32

Named Mutex

A C program that creates a named mutex and uses GetLastError to detect whether another process already holds it.

Mar 31, 1995cppipcwin32

Registry Set Value

A minimal C program that opens a registry key and writes a string value with RegSetValueEx.

Mar 29, 1995cppregistrywin32

Win32 Kill Tasks

A tiny C utility that force-closes every running task with a single ExitWindowsEx(EWX_FORCE) call.

Mar 18, 1995cpputilitywin32

Create Window Control

Helper functions that create STATIC and EDIT controls at runtime with a standard font.

Feb 4, 1995cppwin32

True Wait

A C helper that performs a timed wait on a background thread, flipping a flag when the interval elapses so the caller can keep working meanwhile.

Jan 5, 1995cppwin32
An unhandled error has occurred. Reload 🗙