Fix SQL Server default constraints #298
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes altering column default values. In SQL Server column default values are stored in constraints.
CREATE TABLE
statements with column declarations likesome_column NVARCHAR(50) NOT NULL DEFAULT 'default value'
internally creates a default constraint with an automatically generated name in the the system tablesys.default_constraints
.ALTER TABLE
statements do not support theDEFAULT
clause in column alteration declarations, leading in SQL syntax errors. Thus changing a column's default value is currently not possible.To alter a column's default value, the old column's default constraint hast to be dropped and recreated again. As a default constraint has to be referenced by name to be dropped, we need to create each default constraint with an own unique name. This PR generates separate statements for default constraint declarations. It generates a unique name consisting of the table name and the column name the default constraint is created for.
DF_TABLE_NAME_HASH%_%COLUMN_NAME_HASH%