Skip to content

Support SQL Server ALTER TABLE ADD DEFAULT constraints - #2561

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/sqlserver-default-constraint
Sep 10, 2026
Merged

Support SQL Server ALTER TABLE ADD DEFAULT constraints#2561
manticore-projects merged 1 commit into
JSQLParser:masterfrom
minleejae:fix/sqlserver-default-constraint

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

Fixes #2020

The CREATE TABLE example is already supported on current master. This PR addresses the remaining ALTER TABLE ADD DEFAULT constraint syntax.

Changes

  • Parse ADD [CONSTRAINT name] DEFAULT expression FOR column [WITH VALUES].
  • Represent the default as DefaultConstraint, a NamedConstraint with a structured value expression and target Column, exposed through AlterExpression.getIndex().
  • Reuse table-element traversal/rendering and share DEFAULT rendering between AST and deparser. Custom expression deparsers can rewrite both the default value and target column.
  • Integrate expression and metadata validation, including unnamed defaults and checking a named constraint as a new constraint rather than an existing index.

Existing inline column defaults and ALTER COLUMN SET/DROP DEFAULT remain unchanged. This does not attempt database-level validation of which expressions SQL Server permits as defaults.

Verification

  • Full Gradle check (tests, Checkstyle, PMD, Spotless).
  • Maven clean verify with Java 17.
  • The issue's ALTER TABLE example, quoted identifiers, nested parentheses, functions, sequence defaults, multiple actions, negative syntax, AST mutation, custom deparsing, and metadata validation.

Reference: SQL Server ALTER TABLE table constraints.

@manticore-projects
manticore-projects merged commit d45f796 into JSQLParser:master Sep 10, 2026
8 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] SQLServer Validation fail jsqlparser Version :4.9

2 participants