DoenaSoft.SqlServerDatabaseMeta 2.2.0

dotnet add package DoenaSoft.SqlServerDatabaseMeta --version 2.2.0
                    
NuGet\Install-Package DoenaSoft.SqlServerDatabaseMeta -Version 2.2.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DoenaSoft.SqlServerDatabaseMeta" Version="2.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DoenaSoft.SqlServerDatabaseMeta" Version="2.2.0" />
                    
Directory.Packages.props
<PackageReference Include="DoenaSoft.SqlServerDatabaseMeta" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DoenaSoft.SqlServerDatabaseMeta --version 2.2.0
                    
#r "nuget: DoenaSoft.SqlServerDatabaseMeta, 2.2.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DoenaSoft.SqlServerDatabaseMeta@2.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DoenaSoft.SqlServerDatabaseMeta&version=2.2.0
                    
Install as a Cake Addin
#tool nuget:?package=DoenaSoft.SqlServerDatabaseMeta&version=2.2.0
                    
Install as a Cake Tool

SQL Server Database Meta Reader

NuGet License: MIT

A .NET library that provides read-only access to SQL Server database metadata, enabling you to programmatically discover and analyse the structure of a database.

Supported Frameworks

  • .NET Framework 4.7.2
  • .NET 10.0

Installation

dotnet add package DoenaSoft.SqlServerDatabaseMeta

Or via the Package Manager Console:

Install-Package DoenaSoft.SqlServerDatabaseMeta

Features

Category What is read
Tables and Views Name, type (BASE TABLE / VIEW), MS_Description
Columns Name, data type, ordinal, nullability, identity, default, precision,
scale, max length, collation, MS_Description
Foreign Keys Name, source/target table and columns, column index pairs, MS_Description
Indexes Name, type flags (unique, primary key, clustered), key columns,
included columns, MS_Description
Check Constraints Name, table, SQL definition expression, MS_Description
Scalar Functions Name, schema, full CREATE FUNCTION definition text, MS_Description

Descriptions are read from the MS_Description extended property.

API Overview

Reading table metadata

IMetaReader reader = new MetaReader();

// Option 1: individual credentials
IReadOnlyList<ITableMeta> tables = reader.Read("myServer", "myDatabase", "user", "password");

// Option 2: connection string
IReadOnlyList<ITableMeta> tables = reader.Read("Server=myServer;Database=myDatabase;...");

// Option 3: already-open connection
using var connection = new SqlConnection(connectionString);
connection.Open();
IReadOnlyList<ITableMeta> tables = reader.Read(connection);

Reading scalar-valued functions

IReadOnlyList<IScalarFunctionMeta> functions = reader.ReadScalarFunctions(connectionString);

foreach (IScalarFunctionMeta fn in functions)
{
    Console.WriteLine(fn.Schema + "." + fn.Name);
    Console.WriteLine(fn.Definition);  // full CREATE FUNCTION text
}
foreach (ITableMeta table in tables)
{
    Console.WriteLine(table.Name + " (" + table.Type + ")");

    foreach (IColumnMeta col in table.Columms)
    {
        Console.WriteLine("  " + col.Name + " " + col.DataType
            + (col.IsNullable ? " NULL" : " NOT NULL"));
    }

    foreach (IIndexMeta idx in table.Indices)
    {
        Console.WriteLine("  INDEX " + idx.Name + " [" + idx.Properties + "]");
    }

    foreach (IForeignKeyMeta fk in table.OutgoingForeignKeys)
    {
        Console.WriteLine("  FK " + fk.Name + " -> " + fk.TargetTable.Name);
    }

    foreach (ICheckMeta ck in table.Checks)
    {
        Console.WriteLine("  CHECK " + ck.Name + ": " + ck.Check);
    }
}

Key Interfaces

Interface Description
IMetaReader Entry point; call Read() or ReadScalarFunctions()
ITableMeta Table or view with columns, indexes, keys, and checks
IColumnMeta Column with type info and constraints
IIndexMeta Index with key columns and included columns
IForeignKeyMeta Foreign key with source/target table and column refs
ICheckMeta Check constraint with SQL definition text
IScalarFunctionMeta Scalar UDF with schema and CREATE FUNCTION body
IMetaBase Base interface: MetaId (transient GUID), Name, Description

All collections are IReadOnlyList<T>. MetaReader is non-static and can be subclassed to override Read() or ReadScalarFunctions() for custom behaviour.

Notes

  • Only SQL Server is supported (uses System.Data.SqlClient).
  • MetaId is a transient GUID generated at read time; it is not persisted and will differ between runs.
  • Descriptions are taken from the MS_Description extended property where present.
  • The Queries static class exposes all SQL strings used internally, which may be useful for diagnostics or custom tooling.

License

MIT

Changelog

Version 2.2.0

  • Migrated all data access from XSD typed datasets to raw SqlCommand/SqlDataReader
  • Added IScalarFunctionMeta interface to expose scalar-valued function metadata
  • Added ReadScalarFunctions() overloads to IMetaReader and MetaReader
  • Removed dependency on System.Data.DataSetExtensions

Version 2.1.0

  • Added IncludedColumns property to IIndexMeta to expose non-key covering index columns

Version 2.0.0

  • Multi-targeting support for .NET Framework 4.7.2 and .NET 10.0
  • Updated package references
  • SDK-style project format
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.2.0 94 8/21/2026
2.1.0 95 8/21/2026
1.1.1 309 9/23/2024
1.1.0 248 9/23/2024
1.0.2 507 11/28/2022
1.0.1 551 4/27/2022
1.0.0 532 4/27/2022