Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/A-Point-Systems-ltd/ms-sql-mcp/llms.txt

Use this file to discover all available pages before exploring further.

InsertData executes a single INSERT statement against the connected SQL Server or Azure SQL Database. It is marked ReadOnly=false, Destructive=false in MCP metadata — agents can call it without a destructive-confirmation prompt, though care should still be taken to verify the target table and values before execution.

Parameter

sql
string
required
A complete INSERT T-SQL statement. Both INSERT … VALUES and INSERT … SELECT forms are accepted. Multi-batch scripts separated by GO are not supported. A trailing semicolon is allowed; an internal semicolon between two statements is rejected.

Return value

InsertData returns a DbOperationResult with rowsAffected populated:
{
  "success": true,
  "error": null,
  "rowsAffected": 3
}
rowsAffected reflects the number of rows the INSERT statement inserted, as returned by ExecuteNonQueryAsync. On failure:
{
  "success": false,
  "error": "Violation of PRIMARY KEY constraint 'PK_Orders'. Cannot insert duplicate key in object 'dbo.Orders'."
}
SQL parameters are not supported — values must be embedded as literals in the SQL string. Never interpolate untrusted user input directly into the SQL statement. Doing so creates a SQL injection vulnerability. Always sanitize or validate values before building the INSERT string.

AI Insights integration

On success, InsertData calls QueueInsightDdlProcessing(), which enqueues the same background DDL audit drain used by ExecuteSQL, CreateTable, DropTable, and UpdateData. This is a no-op when USE_INSIGHTS_LAYER=false.

Examples

Single-row INSERT with VALUES

INSERT INTO dbo.Orders (CustomerId, TotalAmount)
VALUES (42, 199.99);

Multi-row INSERT with VALUES

INSERT INTO dbo.Products (ProductName, UnitPrice, StockQty)
VALUES
    ('Widget A', 9.99,  100),
    ('Widget B', 14.99, 50),
    ('Widget C', 4.99,  250);

INSERT … SELECT from another table

INSERT INTO dbo.OrdersArchive (OrderId, CustomerId, OrderDate, TotalAmount)
SELECT OrderId, CustomerId, OrderDate, TotalAmount
FROM   dbo.Orders
WHERE  OrderDate < '2023-01-01';

INSERT with OUTPUT clause to capture generated keys

INSERT INTO dbo.Orders (CustomerId, TotalAmount)
OUTPUT INSERTED.OrderId, INSERTED.OrderDate
VALUES (42, 299.00);
The OUTPUT clause causes SQL Server to return a result set, but ExecuteNonQuery (used internally) still counts rows affected and discards the output rows. If you need to capture INSERTED values, consider using ReadData with an INSERT … OUTPUT … INTO @tmp; SELECT * FROM @tmp pattern wrapped in a stored procedure called via ExecuteSQL.
For bulk loading, prefer multiple batched VALUES rows in a single InsertData call over looping individual calls — SQL Server processes multi-row VALUES lists more efficiently and each call incurs a round-trip.

Build docs developers (and LLMs) love