If you need to insert multiple values into table it can be made with one of these methods:
- write multiple rows after VALUES clause of INSERT command
1 2 3 4 5 6 7 8 9 |
INSERT INTO PhoneNumbers ( PhoneGuid, PhoneNumber, PhoneTypeID ) VALUES (NEWID(), '88001111111', 1), (NEWID(), '88002222222', 2), (NEWID(), '88003333333', 2); |
I used here a thing called table-value constructor. You can read more about it in the MSDN article Table Value Constructor (Transact-SQL)
- use INSERT INTO … SELECT with UNION ALL
1 2 3 4 5 6 7 8 9 10 |
INSERT INTO PhoneNumbers ( PhoneGuid, PhoneNumber, PhoneTypeID ) SELECT NEWID(), '88001111111', 1 UNION ALL SELECT NEWID(), '88002222222', 2 UNION ALL SELECT NEWID(), '88003333333', 2; |
Important! The first method can be used in SQL Server 2008 version or higher.