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.

CreateTable is a typed wrapper for CREATE TABLE operations. Unlike the generic ExecuteSQL tool, it sets ReadOnly=false, Destructive=false in MCP metadata, clearly distinguishing a schema-creation action from destructive mutations. MCP-aware clients can use this distinction to apply lighter confirmation logic for table creation than they would for drops or bulk deletes.

Parameter

sql
string
required
A complete CREATE TABLE T-SQL statement. Schema-qualified table names (e.g. dbo.MyTable) are strongly recommended to avoid ambiguity. The statement is passed directly to SqlCommand.ExecuteNonQueryAsync — no transformation is applied.

Return value

CreateTable returns a DbOperationResult object:
{
  "success": true,
  "error": null,
  "rowsAffected": null
}
On failure the response is:
{
  "success": false,
  "error": "There is already an object named 'MyTable' in the database."
}
rowsAffected is not populated for DDL statements. Use DescribeTable after a successful create to verify the column list, constraints, and indexes were applied as intended.

AI Insights integration

On success, CreateTable calls QueueInsightDdlProcessing() to enqueue a background DDL audit drain and schema-fingerprint reconciliation — the same pipeline triggered by ExecuteSQL. This is automatic when USE_INSIGHTS_LAYER is enabled (the default). The new table will be eligible for baseline insight generation on the next reconciliation pass if INSIGHTS_AUTOPOPULATE is also enabled.

Example

Basic CREATE TABLE

CREATE TABLE dbo.Products (
    ProductId   INT            NOT NULL IDENTITY(1,1) PRIMARY KEY,
    ProductName NVARCHAR(200)  NOT NULL,
    UnitPrice   DECIMAL(10,2)  NOT NULL DEFAULT 0.00,
    StockQty    INT            NOT NULL DEFAULT 0,
    CreatedAt   DATETIME2(0)   NOT NULL DEFAULT SYSUTCDATETIME()
);

CREATE TABLE with a foreign key

CREATE TABLE dbo.OrderLines (
    LineId     INT            NOT NULL IDENTITY(1,1) PRIMARY KEY,
    OrderId    INT            NOT NULL
        CONSTRAINT FK_OrderLines_Orders REFERENCES dbo.Orders(OrderId),
    ProductId  INT            NOT NULL
        CONSTRAINT FK_OrderLines_Products REFERENCES dbo.Products(ProductId),
    Quantity   INT            NOT NULL DEFAULT 1,
    UnitPrice  DECIMAL(10,2)  NOT NULL
);

CREATE TABLE IF NOT EXISTS pattern

SQL Server does not have a native CREATE TABLE IF NOT EXISTS syntax. Use a conditional check before calling CreateTable:
IF NOT EXISTS (
    SELECT 1 FROM sys.tables
    WHERE object_id = OBJECT_ID(N'dbo.AuditLog')
)
CREATE TABLE dbo.AuditLog (
    AuditId    BIGINT         NOT NULL IDENTITY(1,1) PRIMARY KEY,
    EventTime  DATETIME2(7)   NOT NULL DEFAULT SYSUTCDATETIME(),
    EventType  NVARCHAR(100)  NOT NULL,
    Details    NVARCHAR(MAX)  NULL
);
After creating a table, call DescribeTable with the new table name to confirm the schema was applied correctly and to retrieve any AI Insights baseline that was generated for the object.

Build docs developers (and LLMs) love