SchemaSmith Documentation

SchemaTongs - SQL Server (Enterprise)

Extract SQL Server schema into a repository that supports team-scale change management.

SchemaTongs schema extraction tool

Overview

SchemaTongs is the starting point of the SchemaSmith workflow. It connects to a SQL Server database and extracts metadata representing the current state of that database - tables, procedures, views, etc. This metadata becomes the raw material that feeds into the SchemaSmith toolchain for shaping and deploying your desired state across environments. We call this initial process of extracting schema definitions casting the database.

Simply point the application at each of your databases and everything within them will be extracted out to the folder of your choosing.

Where SchemaTongs Fits

  • SchemaTongs extracts your schema into metadata.
  • SchemaHammer provides powerful search and edit capabilities for your metadata.
  • SchemaQuench applies your schema and data metadata to your SQL Servers.
  • DataTongs extracts your seed data into metadata

Quick Start Guide

1. Configure your appSettings.json

Point SchemaTongs at your source database. All object types are extracted by default. Use ObjectList to limit extraction to specific objects:

{
  "Source": {
    "Server": "localhost",
    "Database": "AdventureWorks",
    "User": "",
    "Password": ""
  },
  "Product": {
    "Path": "C:\\SchemaPackage",
    "Name": "AdventureWorks"
  },
  "Template": {
    "Name": "AdventureWorks"
  },
  "ShouldCast": {
    "Tables": true,
    "Schemas": true,
    "UserDefinedTypes": true,
    "UserDefinedFunctions": true,
    "Views": true,
    "StoredProcedures": true,
    "TableTriggers": true,
    "Catalogs": true,
    "StopLists": true,
    "DDLTriggers": true,
    "XMLSchemaCollections": true,
    "ScriptDynamicDependencyRemovalForFunctions": false,
    "ObjectList": ""
  }
}
2. Run SchemaTongs

Execute SchemaTongs from the command line and the casting process will begin.

> SchemaTongs
3. Shape your metadata

Move on to editing your metadata with SchemaHammer.

See the SchemaTongs Walkthrough to help you get started with the tool.

Tip

The same concepts for how to override appSettings.json for SchemaQuench apply to SchemaTongs. You can also use Command Line Options to specify the log file location or an alternate config file.

What is Exported

SchemaTongs extracts 11 object types from SQL Server. Tables are exported as JSON definitions; all other objects are exported as SQL scripts.

Object Type Directory Format
TablesTables/JSON (schema.table.json)
SchemasSchemas/SQL (schema.sql)
User-Defined Data TypesDataTypes/SQL
User-Defined Table TypesDataTypes/SQL
FunctionsFunctions/SQL (schema.name.sql)
ViewsViews/SQL (schema.name.sql)
Stored ProceduresProcedures/SQL (schema.name.sql)
Table TriggersTriggers/SQL (schema.table.trigger.sql)
DDL TriggersDDLTriggers/SQL
Full-Text CatalogsFullTextCatalogs/SQL
Full-Text Stop ListsFullTextStopLists/SQL
XML Schema CollectionsXMLSchemaCollections/SQL

All directories are relative to Product:Path/Templates/Template:Name/.

Encrypted objects (procedures, functions, views, and triggers with WITH ENCRYPTION) cannot be scripted. SchemaTongs skips these objects and logs a warning for each one encountered.

Package Initialization

On the first cast to a new product path, SchemaTongs creates Product.json and Template.json with default values, along with JSON schema files in .json-schemas/ for editor validation. All script folders are created physically on disk.

On subsequent casts, Product.json and Template.json are never overwritten — only the extracted object scripts and table JSON files are refreshed. New templates are added to the product's TemplateOrder automatically.

After your first cast, review and customize Product.json and Template.json, particularly ValidationScript, DatabaseIdentificationScript, and VersionStampScript, to match your deployment needs.

Extraction Details

ObjectList Filtering

By default, SchemaTongs extracts all objects from the database. Set ShouldCast:ObjectList to a comma or semicolon-separated list of object names to limit extraction to specific objects only.

Matching is case-insensitive and supports both bare names and schema-qualified names:

  • "ObjectList": "MyTable" — matches dbo.MyTable, sales.MyTable, etc.
  • "ObjectList": "sales.MyTable" — matches only sales.MyTable
  • "ObjectList": "MyTable,MyProc,sales.OrderView" — matches multiple objects

ObjectList uses exact string matching only — no wildcards or regular expressions. The filter applies to all object types (tables, views, procedures, etc.).

Excluded Objects

The following objects are automatically excluded from extraction:

Exclusion Reason
Microsoft system objects Objects with is_ms_shipped = 1 in sys.objects.
SchemaSmith schema Helper infrastructure installed by SchemaTongs itself (functions, procedures, tables).
System schemas Schemas with schema_id <= 4 (dbo, guest, INFORMATION_SCHEMA, sys) and db_* patterns.
Replication tables Tables matching MSPeer_% or MSPub_% patterns.
Diagram metadata dtproperties and sysdiagrams tables (SSMS diagram storage).

Helper Infrastructure

Before extraction, SchemaTongs installs helper objects in a [SchemaSmith] schema on the source database. These objects are used during extraction and deployment. They include:

  • Functions: fn_StripParenWrapping, fn_StripBracketWrapping, fn_SafeBracketWrap, fn_FormatJson — string manipulation and JSON formatting helpers.
  • Procedures: GenerateTableJSON — extracts complete table definitions as JSON. PrintWithNoWait — real-time console output during operations. Plus table quench procedures used by SchemaQuench at deployment time.
  • Table: CompletedMigrationScripts — tracks which migration scripts have been executed to prevent re-execution.

These objects are excluded from extraction output automatically. The SkipKindlingForge command-line argument can skip this installation step if the helpers are already present.

Re-extraction Preservation

When SchemaTongs re-extracts into an existing schema package, it preserves user-configured properties that were added after the initial extraction. This means you can safely re-run SchemaTongs without losing your customizations.

Preserved on table JSON files:

  • Data delivery properties: ContentFile, MergeType, MatchColumns, MergeFilter, MergeDisableTriggers
  • OldName (for tracking table renames)
  • All custom properties on tables, columns, indexes, foreign keys, and check constraints

Components are matched by name (case-insensitive) or by OldName for renamed objects. Schema structure is always refreshed from the database; only user-defined metadata is preserved.

Script Formatting

Programmable objects (functions, views, procedures, triggers) are extracted with their original SET ANSI_NULLS and SET QUOTED_IDENTIFIER settings, followed by a CREATE OR ALTER statement. The script body preserves the exact formatting from the database.

All line endings are normalized to \r\n (Windows CRLF) regardless of the source database platform.

ShouldCast Flags Reference

Flag Default Description
Tables true Extract table definitions as JSON files. Includes columns, indexes, foreign keys, check constraints, and extended properties.
Schemas true Extract user-defined schemas (excludes system schemas like dbo, sys, guest).
UserDefinedTypes true Extract user-defined alias types and table types.
UserDefinedFunctions true Extract scalar functions (FN), inline table-valued functions (IF), and multi-statement table-valued functions (TF).
Views true Extract view definitions.
StoredProcedures true Extract stored procedure definitions.
TableTriggers true Extract DML triggers on tables (parent_class = 1).
Catalogs true Extract full-text catalogs.
StopLists true Extract full-text stop lists.
DDLTriggers true Extract database-level DDL triggers (parent_class = 0).
XMLSchemaCollections true Extract XML schema collections.
ScriptDynamicDependencyRemovalForFunctions false When enabled, each function script includes a preamble that dynamically drops computed column constraints, indexes, and dependencies before the CREATE OR ALTER. SchemaQuench restores them when processing managed tables. Use when functions are referenced by computed columns or filtered indexes.
ObjectList "" Comma or semicolon-separated list of object names to extract. Leave empty to extract all objects. See Extraction Details.

Additional Resources

See Also