{"record":{"id":"4c878756b98440dc","repo":"apache/seatunnel","slug":"error-executing-sqlserver-sql-ddlsql","errorCode":null,"errorMessage":"Error executing SqlServer SQL: ${ddlSQL}","messagePattern":"Error executing SqlServer SQL: (.+?)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java","lineNumber":518,"sourceCode":"            case SQLSERVER_TEXT:\n            case SQLSERVER_NTEXT:\n            case SQLSERVER_XML:\n            case SQLSERVER_UNIQUEIDENTIFIER:\n            case SQLSERVER_SQLVARIANT:\n                return true;\n            default:\n                return false;\n        }\n    }\n\n    private void executeDDL(Connection connection, List<String> ddlSQL) throws SQLException {\n        try (Statement statement = connection.createStatement()) {\n            for (String sql : ddlSQL) {\n                log.info(\"Executing SqlServer SQL: {}\", sql);\n                statement.execute(sql);\n            }\n        } catch (SQLException e) {\n            throw new SQLException(\"Error executing SqlServer SQL: \" + ddlSQL, e.getSQLState(), e);\n        }\n    }\n\n    private String buildColumnCommentSQL(TablePath tablePath, Column column) {\n        return String.format(\n                \"EXEC %s.sys.sp_updateextendedproperty 'MS_Description', N'%s', 'schema', N'%s', \"\n                        + \"'table', N'%s', 'column', N'%s';\",\n                tablePath.getDatabaseName(),\n                column.getComment(),\n                tablePath.getSchemaName(),\n                tablePath.getTableName(),\n                column.getName());\n    }\n\n    private boolean columnIsNullable(Connection connection, TablePath tablePath, String column)\n            throws SQLException {\n        // Prefix with the target database name so the query works even when the JDBC connection\n        // is connected to a different database (e.g. master with no databaseName in the URL).","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/sqlserver/SqlServerDialect.java#L500-L536","documentation":"Thrown by SqlServerDialect.executeDDL (called from applySchemaChange) when one of the generated DDL statements fails to execute against SQL Server. The full DDL list and the driver's SQLState are wrapped into the new exception.","triggerScenarios":"applySchemaChange submits schema-evolution statements (ADD/MODIFY/DROP COLUMN, comments via sp_updateextendedproperty) and SQL Server rejects one — bad identifier quoting, unsupported type mapping, existing column name, or insufficient ALTER permissions.","commonSituations":"Schema evolution against tables owned by another schema; column type changes unsupported by SQL Server; missing ALTER permission on the table; special characters in column names/comments breaking quoting.","solutions":["Read the chained cause exception for the exact SQLState and SQL Server error message","Run the failing DDL manually in SSMS to reproduce and fix syntax/quoting issues","Grant ALTER permission on the table to the connector user","Check that target column names/types are compatible with the SQL Server type mapping"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Verify ALTER permission and reproduce DDL manually first\nSELECT HAS_PERMS_BY_NAME(DB_NAME() + '.dbo.MyTable', 'OBJECT', 'ALTER');","typeGuard":null,"tryCatchPattern":"try {\n    applySchemaChange(event);\n} catch (SQLException e) {\n    log.error(\"DDL failed: {} sqlstate={}\", e.getMessage(), e.getSQLState(), e.getNextException());\n}","preventionTips":["Grant ALTER permission on target tables","Test DDL statements in SSMS before enabling schema evolution","Avoid special characters in column names or escape them","Map upstream types to SQL Server-compatible types"],"tags":["jdbc","sqlserver","ddl","schema-evolution"],"backgroundTag":"sql-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}