Last active
August 24, 2018 18:56
-
-
Save mocella/205168cc4a177a2ae1ac5925ebe9934c to your computer and use it in GitHub Desktop.
Steps to modify a column in a temporal table in Sql Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Steps to alter a column in a Temporal Table | |
| e.g. Table "Employee" versioned by "EmployeeHistory", change column "LastName" from Null to Not Null | |
| */ | |
| ALTER TABLE [dbo].[Employee] SET (SYSTEM_VERSIONING = OFF); | |
| -- fix any null entries in the primary and history tables: | |
| UPDATE dbo.Employee SET [LastName] = '' WHERE [LastName] IS NULL; | |
| EXEC('UPDATE dbo.EmployeeHistory SET [LastName] = '''' WHERE [LastName] IS NULL'); | |
| ALTER TABLE [dbo].[Employee] | |
| SET | |
| ( | |
| SYSTEM_VERSIONING = ON (HISTORY_TABLE = [dbo].[EmployeeHistory]) | |
| ); | |
| ALTER TABLE dbo.Employee ALTER COLUMN [LastName] nvarchar(255) NOT NULL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment