A
A
avatar872019-01-24 15:40:57
Microsoft Azure
avatar87, 2019-01-24 15:40:57

MS SQL how to update schema with minimal service stop?

Azure has a database with a performance of 100 dtu in which there is a table with ~ 100 million rows. You need to change the schema of this table. Stopping the service and updating the scheme in the forehead takes ~ 2 hours. How can I reduce schema update time? What techniques are used to update the schema on the fly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2019-01-24
@avatar87

What does AZURE support say?

updating the scheme in the forehead takes ~ 2 hours
Adding a field via ALTER TABLEADDtakes little time. Therefore, it is faster to add a field and transfer data than to recreate a table with data transfer. I.e
ALTER TABLE [Table] ADD [ColumnTemp] DECIMAL (21,8)
GO
UPDATE [Table] SET [ColumnTemp] = [Column]
GO
ALTER TABLE [Table] DROP COLUMN [Column]
GO
ALTER TABLE [Table] ADD [Column] DECIMAL (21,8)
GO
UPDATE [Table] SET [Column] = [ColumnTemp]
GO
ALTER TABLE [Table] DROP COLUMN [ColumnTemp]
GO
Should be faster.
Or
ALTER TABLE [Table] ADD [ColumnTemp] DECIMAL (21,8)
GO
UPDATE [Table] SET [ColumnTemp] = [Column]
GO
ALTER TABLE [Table] DROP COLUMN [Column]
GO
EXEC sp_rename '[Table].[ColumnTemp]' '[Column]' 'COLUMN'
GO

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question