When SQL Server throws Error 113 ("Missing end comment mark"), it means your T-SQL script contains a comment block (starting with `--` or `/*`) that lacks its closing marker (`*/`). This simple syntax error halts execution and prevents your query from running. Here’s how to diagnose and fix it in minutes, with actionable steps for both scripts and stored procedures.

What You'll Need

  • Access to SQL Server Management Studio (SSMS), SQL Server Command Line, or the query tool of your database client
  • A text editor (like Visual Studio Code, Notepad++, or Word) for reviewing and editing scripts
  • The SQL Server error log (for advanced troubleshooting)

Step-by-Step

  1. Identify the line causing the error
    1. Open your SQL script in your preferred tool (SSMS, Command Prompt, or editor).
    2. Run the script *incrementally*—execute one line at a time until the error appears. This isolates the problematic comment block.
    3. In SSMS, use F5 or the "Execute Query" button to run line-by-line.

    If the error persists after line-by-line execution, the issue might be in a stored procedure or function. In SSMS:

    • Right-click the object → Execute.
    • Run it in a new query window for granular line-by-line inspection.

  2. Locate the unclosed comment block
    1. Search for unpaired comment markers in your script. For `--` comments, ensure every line starts with `--` until the end of the file. For `/* */` blocks:
      • Search for /* but */ appears nowhere.
      • Or search for */ but /* exists earlier.
    2. Use SQL Server's built-in syntax highlighting (SSMS) or regex tools to flag mismatches: Find what: /\*/ (for unclosed `/*` blocks) Find what: ^\s*--.*$ (for dangling `--` lines).
  3. Fix the comment syntax
    1. For dangling `--` comments:
      • Remove the extra `--` or add `*/` before it to terminate the block: -- This is a comment -- Extra line without termination (WRONG) -- This is a comment -- */ (WRONG: terminates previous block) -- Add: /* */
    2. For unclosed `/* */` blocks:
      • Find the unmatched `/*` and add `*/` at the end of the file: /* This block starts here -- No closing */ (WRONG) /* This block starts here */ (ADD THIS)
      • Or wrap the dangling lines in a `*/` before them: /* This block -- /* WRONG: Nested without termination -- */
  4. Test the corrected script
    1. Run the fixed script again in your tool. If it’s a stored procedure, drop it and recreate it with the fixes.
    2. For large scripts, compare the error log (via SSMS tools > Object Explorer > Error Logs) before/after. Look for the line number the error reports.

Common Mistakes

  • Nested comments without termination

    Example: /* Outer comment /* Inner comment (WRONG: No closing */) must be rewritten as /* Outer comment */ /* Inner comment */ or /* Outer comment /* Inner comment */.

  • Confusing `--` with `/* */`

    Mistaking a single-line comment for a block note adds unintended `--` lines: /* Comment block -- This is wrong! turns into -- Comment block (WRONG: Terminates the block).

  • Copy-pasting scripts

    Copying code from online tutorials often includes stray comment markers. Always inspect the original source.

Tips

  1. Use SSMS's "SQL Server Object Explorer" to browse stored procedures. Right-click → Execute to test them individually.
  2. Enable SQL Server syntax highlighting (SSMS > Tools > Options > Text Editor > Transact-SQL > Syntax highlighting). It flags dangling comments visually.
  3. Comment/Uncomment with caution
    • Use a dedicated block comment (e.g., -- ==== BEGIN EXAMPLE ====) when commenting out large sections to avoid syntax errors.
    • Avoid commenting out procedures—uncomment them entirely to avoid nested issues.
  4. Script version control
    • Use tools like Git to track changes before running scripts. A comment error in a merge conflict can be easier to debug.

Troubleshooting

If fixing the script doesn’t resolve the error, check these advanced steps:

  1. Verify SQL Server is not parsing intermediate steps
    1. Enable OPTION OPTIMIZE FOR UNKNOWN in your query (before the first line) to force SQL Server to parse dynamically: SET QUOTED_IDENTIFIER ON; OPTION OPTIMIZE FOR UNKNOWN;
    2. If the error persists, the issue might be a script corruption (e.g., trailing whitespace). Recreate the script from the original source.
  2. Inspect the error log
    1. In SSMS, go to Tools > Error Logs to see if the error continues, or check the ERRORLOG database directly: SELECT * FROM sys.server_errorlogs WHERE message_id = 113;
    2. Look for repeated errors—this may indicate a broader syntax issue (e.g., unescaped quotes or special characters).
  3. Recreate the object
    1. If the error occurs in a stored procedure, drop it and recreate it without the problematic comment: DROP PROCEDURE IF EXISTS YourProcedure; GO CREATE PROCEDURE YourProcedure AS BEGIN SELECT * FROM YourTable; END;
    2. For tables/views, run DROP first if they’re corrupted by the comment error.
  4. Check for hidden characters
    1. Copy the problematic section into a clean editor like Notepad++ or VS Code. Use the "Show Bytes" or "Show Whitespace" feature to detect invisible characters (e.g., non-breaking spaces) that might interfere with comment syntax.

Frequently Asked Questions

How do I know if a comment is causing the error before I fix it?

Run your script in SSMS’s "Execute Query" mode, line-by-line, or use F5 (step-over). The error will surface at the first malformed comment block. For stored procedures, attach the script to a new query window so you can inspect line-by-line.

Can I use a single `--` to close a multi-line `/* */` comment?

No. A single `--` terminates the current SQL statement (e.g., a query), not a comment block. For example: /* This is a block */ -- WRONG: Terminates the block prematurely. Use only `*/` to close blocks.

What if I’m using a template with mixed comment styles?

Convert all comments to a single style (e.g., only `--` or only `/* */`). Merging styles can create dangling markers. Example: -- Single-line (consistent) /* Block-style (remove all other markers) */

Does SQL Server automatically fix missing comment marks?

No. SQL Server complains with Error 113—the error message itself does not auto-correct. You must manually add `*/` or remove `--` lines.

How do I debug a script with Errors 113 and 1806 (invalid object name)?

These often appear together. First resolve Error 113 as above. Then: 1. Check if the object name is misspelled or misspelled in a script embedded in your query (e.g., SELECT * FROM InvalidTableName;). 2. Validate object existence with: SELECT name FROM sys.objects WHERE name LIKE '%TableName%'; 3. Drop and recreate the object if corrupted.

Can I use SQL Server’s live parsing feature to catch these errors?

Yes. Enable query hint OPTION (RECOMPILE) to force SQL Server to parse dynamically, flagging syntax errors early. Example: SET QUOTED_IDENTIFIER ON; OPTION (RECOMPILE); SELECT /* This comment will error */ 1;