Skip to content

feat: TSQL IDENTITY, named UNIQUE/FOREIGN KEY constraints and trailing comma - #380

Open
jtrv wants to merge 1 commit into
DerekStride:mainfrom
jtrv:tsql-constraints
Open

jtrv wants to merge 1 commit into
DerekStride:mainfrom
jtrv:tsql-constraints

Conversation

@jtrv

@jtrv jtrv commented Sep 24, 2026 •

Copy link
Copy Markdown

SQL Server CREATE TABLE scripts hit three gaps. Each one produces an ERROR node that swallows the rest of the table definition:

CREATE TABLE dbo.assembly (
  id int IDENTITY (1, 1) NOT NULL,                        -- IDENTITY column constraint
  customer_id int NOT NULL,
  CONSTRAINT pk_assembly PRIMARY KEY (id),
  CONSTRAINT fk_assembly_customer FOREIGN KEY (customer_id)
    REFERENCES dbo.customer(id),                          -- named FOREIGN KEY
  CONSTRAINT uq_assembly UNIQUE (customer_id),            -- named UNIQUE
);                                                        -- trailing comma

Changes:

  • keyword_identity: a new column constraint, IDENTITY with an optional (seed, increment). The two values are exposed as seed and increment fields. Also added to highlights.scm next to keyword_auto_increment.
  • _constraint_literal: after CONSTRAINT <name> it now accepts _key_constraint (UNIQUE / FOREIGN KEY … REFERENCES) as well as PRIMARY KEY and CHECK.
  • column_definitions: accepts an optional trailing , before ). The comma after the last constraint left the parser unable to tell whether another constraint or the closing ) comes next, so [$.constraints] is added to conflicts to let it try both.

The new corpus test is in test/corpus/create.txt. All existing tests still pass. Unchanged:

  • GENERATED ALWAYS AS IDENTITY produces the same tree as before.
  • identity still works as a column name.

🤖 Generated with Claude Code

…g comma

SQL Server table definitions commonly use:
- IDENTITY or IDENTITY (seed, increment) as a column constraint
- CONSTRAINT <name> UNIQUE (...) and CONSTRAINT <name> FOREIGN KEY (...)
  REFERENCES ..., where only PRIMARY KEY and CHECK were accepted after a
  constraint name
- a trailing comma before the closing parenthesis of CREATE TABLE

Each of these produced an ERROR node that swallowed the rest of the table
definition.

This branch has not been deployed

No deployments
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.

1 participant