SQLServerSchemaExtractor 1.0.2
dotnet add package SQLServerSchemaExtractor --version 1.0.2
NuGet\Install-Package SQLServerSchemaExtractor -Version 1.0.2
<PackageReference Include="SQLServerSchemaExtractor" Version="1.0.2" />
<PackageVersion Include="SQLServerSchemaExtractor" Version="1.0.2" />
<PackageReference Include="SQLServerSchemaExtractor" />
paket add SQLServerSchemaExtractor --version 1.0.2
#r "nuget: SQLServerSchemaExtractor, 1.0.2"
#:package SQLServerSchemaExtractor@1.0.2
#addin nuget:?package=SQLServerSchemaExtractor&version=1.0.2
#tool nuget:?package=SQLServerSchemaExtractor&version=1.0.2
SQL Server Schema Extractor
A .NET library that extracts SQL Server database schemas and converts them to JSON. The JSON output is designed for use in prompts, allowing large language models (LLMs) to translate natural language queries into SQL statements.
Features
- Extracts schema from SQL Server databases.
- Outputs schema in JSON or YAML format.
- Configurable via
appsettings.json.
Usage
Configure Connection and Schema
Edit
appsettings.json(orappsettings.Local.json) to set your database connection and schema extraction options:"DatabaseConnection": "your-connection-string-here", "Nl2SqlConfig": { "database": { "description": "Your database description", "schemas": [ { "name": "SchemaName", "tables": [ "Table1", "Table2" ] } ] } }Usage
To support configuration, ASP.NET Core APIs have it built-in, but console apps require adding the Microsoft.Extensions.Configuration package and manually setting up sources like appsettings.json.
var config = configuration.GetSection("Nl2SqlConfig").Get<Nl2SqlConfigRoot>();
var connectionString = configuration["DatabaseConnection"];
var sqlHarness = new SqlSchemaProviderHarness(connectionString, config.Database.Description);
var jsonSchema = await sqlHarness.ReverseEngineerSchemaJSONAsync(config).ConfigureAwait(false);
Additional Notes
Adding column descriptions is crucial for large language models (LLMs) to translate natural language queries into SQL statements accurately.
To add column descriptions to your database metadata, use the sp_addextendedproperty stored procedure.
Example:
EXEC sp_addextendedproperty
@name = N'MS_Description',
@value = N'This column stores the user email address',
@level0type = N'SCHEMA', @level0name = 'dbo',
@level1type = N'TABLE', @level1name = 'Users',
@level2type = N'COLUMN', @level2name = 'Email';
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- Microsoft.Data.SqlClient (>= 6.0.2)
- System.Linq.Async (>= 6.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.