TiCodeX / SQLSchemaCompare

TiCodeX SQL Schema Compare
GNU General Public License v3.0
15 stars 0 forks source link

Option to generate update code on new NOT NULL columns #37

Closed drebrez closed 4 months ago

drebrez commented 7 months ago

When there is a new NOT NULL column the migration script is generated as:

ALTER TABLE [dbo].[ExampleTable] ADD [ExampleColumn] [bit] NOT NULL

in real case scenarios, the table is probably not empty and the sql will probably fail.

We could add a setting option to generate the above line like this instead:

ALTER TABLE [dbo].[ExampleTable] ADD [ExampleColumn] [bit] NULL
GO
UPDATE [dbo].[ExampleTable] SET [ExampleColumn] = 0   <-----   some default or something to let the user know it has to write manually
GO
ALTER TABLE [dbo].[ExampleTable] ALTER COLUMN [ExampleColumn] [bit] NOT NULL
GO