Warning
Error Code: 3779

MySQL Error 3779: Deprecated Nested Comments

📦 MySQL
📋

Description

This error indicates that your SQL code uses nested C-style comments, a syntax that is no longer recommended. MySQL issues this warning when it encounters `/* ... /* ... */ ... */` constructs, signaling that support for them will be removed in a future release. It typically occurs during query execution or script parsing.
💬

Error Message

Nested comment syntax is deprecated and will be removed in a future release.
🔍

Known Causes

3 known causes
⚠️
Legacy SQL Code
Older SQL scripts or applications might contain nested C-style comments from a time when this syntax was more commonly used or tolerated.
⚠️
Manual Syntax Errors
Developers might inadvertently write nested comments, especially when commenting out large blocks of code that already contain comments.
⚠️
Third-Party Tool Output
Some database migration tools, code generators, or IDEs might produce SQL with nested comments, unaware of MySQL's deprecation.
🛠️

Solutions

3 solutions available

1. Replace Nested Comments with Single-Line Comments easy

Convert all instances of nested `/* ... /* ... */ ... */` comments to single-line `/* ... */` comments.

1
Locate all SQL files and stored procedures/functions that contain nested comments.
2
Manually edit each file and replace any nested comment blocks with equivalent single-line comments. For example, change `/* Outer comment /* Inner comment */ */` to `/* Outer comment -- Inner comment */` (if the inner comment is a single line) or `/* Outer comment */ /* Inner comment */` (if the inner comment needs to be preserved as a separate comment).
/* Outer comment /* Inner comment */ */
-- Becomes:
/* Outer comment */
/* Inner comment */
3
Alternatively, if the inner comment's content is not critical, you can simply remove the inner comment delimiters. For example, `/* Outer comment /* Inner comment */ */` can become `/* Outer comment Inner comment */`.
/* Outer comment /* Inner comment */ */
-- Becomes:
/* Outer comment Inner comment */
4
Save the modified files and re-deploy your schema or application code.

2. Use `--` for Single-Line Comments easy

Replace nested comment blocks with the standard SQL single-line comment syntax (`--`).

1
Identify SQL code segments that use nested comments.
2
Replace the entire nested comment block with a single `--` comment. This is suitable if the entire block is intended as a comment and not a multi-line explanation.
/* This is a nested comment
   /* which is now deprecated */
   and needs to be fixed. */
-- Becomes:
-- This is a comment that was previously nested.
3
Ensure that the `--` comment is placed on its own line or at the end of a statement. Note that `--` comments end at the end of the line.
4
Test your SQL queries and application code after making these changes.

3. Automated Scripting for Comment Conversion medium

Use scripting to automatically find and replace deprecated nested comments across your codebase.

1
Install a text processing tool like `sed` (available on Linux/macOS) or use PowerShell on Windows.
sudo apt-get install sed  # For Debian/Ubuntu
brew install sed          # For macOS with Homebrew
2
Create a backup of your SQL files before running any automated script.
3
Use `sed` to find and replace nested comments. This command will find patterns like `/* ... /* ... */ ... */` and replace them with single-line comments or by removing the inner comment markers. This specific `sed` command aims to simplify nested comments by removing the inner `/*` and `*/` and keeping the outer `/* */` and its content.
find /path/to/your/sql/files -type f -name '*.sql' -exec sed -i 's/\/\*\s*\/\*.*\*\/\s*\*\//\/\*/g' {} +
4
For more complex scenarios or to convert to `--` comments, a more sophisticated script might be needed, potentially involving regular expressions that handle multi-line replacements or a scripting language like Python.
5
After running the script, manually review the changes in critical SQL files and test thoroughly.
🔗

Related Errors

5 related errors