-- Insert Multiple Values into SQL ServerCREATE TABLE #SQLAuthority (ID INT, Value VARCHAR(100));
Method 1: Traditional Method of INSERT…VALUE
-- Method 1 - Traditional InsertINSERT INTO #SQLAuthority (ID, Value)VALUES (1, 'First');INSERT INTO #SQLAuthority (ID, Value)VALUES (2, 'Second');INSERT INTO #SQLAuthority (ID, Value)VALUES (3, 'Third');
Clean up
-- Clean upTRUNCATE TABLE #SQLAuthority;
Method 2: INSERT…SELECT
-- Method 2 - Select Union InsertINSERT INTO #SQLAuthority (ID, Value)SELECT 1, 'First'UNION ALLSELECT 2, 'Second'UNION ALLSELECT 3, 'Third';
Clean up
-- Clean upTRUNCATE TABLE #SQLAuthority;
Method 3: SQL Server 2008+ Row Construction
-- Method 3 - SQL Server 2008+ Row ConstructionINSERT INTO #SQLAuthority (ID, Value)VALUES (1, 'First'), (2, 'Second'), (3, 'Third');
Clean up
-- Clean upDROP TABLE #SQLAuthority;
No comments:
Post a Comment