/sql-server-query:sql-server-queryfrom sql-server-query
Ad-hoc queries against the SQL Server database of any .NET application via sqlcmd on Windows — find the connection string in the project yourself, build the command, read-only by default. Trigger: 'look in the database', 'search the database', 'check in SQL', 'what's the structure of this table'.
Ships in sql-server-query. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Goal: with no prior knowledge of the project, find the database connection, connect
with sqlcmd, and run queries. Read-only by default.
Search in this order (Grep across the repository):
appsettings.Development.json, appsettings.development.json,
appsettings.*.json, appsettings.json — the ConnectionStrings key or the
patterns Data Source= / Server=.csproj has a <UserSecretsId> element, check
%APPDATA%\Microsoft\UserSecrets\<id>\secrets.jsondocker-compose*.yml, .env, launchSettings.json (environment variables of
the form ConnectionStrings__...)If you find more than one connection string, ask the user which database is the right one — don't guess (unless it's obvious from context, e.g. the only development string).
You recognize them by packages.config, web.config/app.config, and a .csproj
with <TargetFrameworkVersion>v4.x</TargetFrameworkVersion>.
Where to look for the connection string:
web.config → the <connectionStrings> element. Watch
out for config transforms — Web.Debug.config / Web.Release.config /
Web.<env>.config can override the value per environment via
xdt:Transform="SetAttributes"; for local development the base web.config
or the Debug transform usually applies.app.config
in the project; after the build the same content lives in
bin\...\<AppName>.exe.config.app.config is IGNORED at runtime — the config
of the startup project (exe or web) applies. Always search there.metadata=res://*/Model.csdl|...;provider connection string="Data Source=..." —
extract the actual SQL connection string from the inner
provider connection string part.<connectionStrings> (you see configProtectionProvider=... and
<EncryptedData>): decrypt with
& "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_regiis.exe" -pdf "connectionStrings" "C:\path\to\folder\with\web.config"
(requires admin rights on the machine where it was encrypted) — or ask the
user for the values.machine.config, or <appSettings> with a key like ConnStr.Connection quirks in legacy projects:
Data Source=(LocalDB)\MSSQLLocalDB or (LocalDB)\v11.0 → LocalDB; sqlcmd
connects the same way (-S "(LocalDB)\MSSQLLocalDB" -E); start the instance if
needed with sqllocaldb start MSSQLLocalDB (list: sqllocaldb info).AttachDbFilename=|DataDirectory|\Database.mdf → the database is a file in
App_Data; connect to the LocalDB/Express instance and find the database by
file name (SELECT name, physical_name FROM sys.master_files).Data Source=.\SQLEXPRESS → local SQL Server Express instance.Provider=SQLOLEDB / SQLNCLI (OLE DB strings, e.g. classic ADO): ignore
Provider=, parse the rest (Data Source, Initial Catalog, User ID…) the
same way.-C doesn't help, add -N o (disable encryption) or use the
classic ODBC sqlcmd that ships with SSMS.Data Source= / Server= → server (careful: a named instance contains \,
e.g. HOST\SQL2022)Initial Catalog= / Database= → databaseUser ID= + Password= → SQL authentication (-U / -P)Integrated Security=True / Trusted_Connection=True → Windows authentication
(-E); on Windows this normally just worksTrustServerCertificate=True / Encrypt=False → add -C (and, if needed,
-N o with go-sqlcmd)Get-Command sqlcmd
If it's missing, install the modern go-sqlcmd:
winget install sqlcmd
(Alternative: sqlcmd also ships with SQL Server Management Studio or the "Microsoft Command Line Utilities for SQL Server" package.)
Windows authentication:
sqlcmd -S "HOST\INSTANCE" -E -d DatabaseName -C -Q "SET NOCOUNT ON; SELECT TOP 10 * FROM schema.TableName"
SQL authentication:
sqlcmd -S "HOST\INSTANCE" -U Username -P "password" -d DatabaseName -C -Q "..."
For machine-readable output add: -h -1 -W -s "|" and put SET NOCOUNT ON; in
the query.
PowerShell notes:
\ (named instances),-C; if that doesn't help, with go-sqlcmd
also add -N o.-- list of tables
SELECT TABLE_SCHEMA + '.' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' ORDER BY 1;
-- columns of a table
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'schema' AND TABLE_NAME = 'TableName' ORDER BY ORDINAL_POSITION;
-- find a table/column by name
SELECT TABLE_SCHEMA + '.' + TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%search%';
-- definition of a stored procedure / view
EXEC sp_helptext 'schema.ProcedureName';
-- foreign key relations of a table
EXEC sp_fkeys @pktable_name = 'TableName', @pktable_owner = 'schema';
INSERT/UPDATE/DELETE/ALTER/DROP/EXEC
(except sp_helptext, sp_fkeys and similar), unless the user explicitly
requests it for one specific statement.TOP N — don't pull whole tables.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub ulebule/claude-skills --plugin sql-server-queryOther plugins' skills for the same job