Skip to content

ALTER TABLE ... DEFAULT without constraint name fails to parse #2

@marcosjom

Description

@marcosjom

Hi ha1tch,

Thanks for this library, it is saving me a lot of time for a db migration.

I'm opening few issues where the library is failing to parse code generated by SQL Server's "Generate Scripts..." option. Once I finish my current migration I expect to spend some time studying your code to send solution feedbacks. Meanwhile I'm opening the issues after confirming the current TSQL specs allows my failing cases.

Failing sample:

ALTER TABLE [dbo].[myTable] ADD  DEFAULT ('') FOR [myField]

Errors:

Error: line 1, col 45: no prefix parse function for ) found
Error: line 1, col 47: no prefix parse function for FOR found

Cause isolation:
By adding a constraint name "ADD CONSTRAINT [DF_myTable_myField]" in the middle the parsing succeeds.

Should the sample be valid?

The definition of "ALTER TABLE table_constraint" for SQL Server 2016 and 2025 starts with:
[ CONSTRAINT constraint_name ]
...

making optional the "missing" part.

Please note: from the many many ALTER TABLE statements generated for my migration, only two had missing "[ CONSTRAINT constraint_name ]".

Saludos,
Marcos

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions