SQL multiple inserts are lengthy and time consuming. Today my team lead guided me how to make it less painful.
We can use UNION ALL. Instead of typing INSERT INTO each time we can UNION ALL.
e.g.
USE [MC_MRR]
GO
INSERT INTO [MC_MRR].[MSR] (Column 1, Column 2, Column 3)
SELECT 'Prevention', 'PR', 'Overcome Risk'
UNION ALL
SELECT 'CheckUp', 'CU', 'Calculate Risk'
UNION ALL
SELECT 'Treatment', 'TR', 'Risk Discovered'
UNION ALL
SELECT 'Diagnosis', 'DG', 'Need Constant Support'
GO
The result for the above script will be the same as
USE [MC_MRR]
GO
INSERT INTO [MC_MRR].[MSR] (Column 1, Column 2, Column 3)
SELECT 'Prevention', 'PR', 'Overcome Risk'
INSERT INTO [MC_MRR].[MSR] (Column 1, Column 2, Column 3)
SELECT 'CheckUp', 'CU', 'Calculate Risk'
GO
No comments:
Post a Comment