In our daily operations, we have to insert multiple records to a table in the database at a time, but the first thought is to copy and paste n multiple repeated insert into statements, in case an error occurs when a semicolon or multiple Commas are missing, it will be a waste of time and work.
In addition to the method mentioned above, there are actually two methods, which are simpler than the previous one.
The first is the previous method:
Insert into mytable (ID, name) values (1 ,'123'); Insert into mytable (ID, name) values (2 ,'456'); Insert into mytable (ID, name) values (3 ,'789');
The second method is to use Union all for insert operations:
Insert into mytable (ID, name) Select 4 ,'000'Union allselect 5 ,'001'Union allselect 6 ,'002'
Is it easier than the first method? It is said to be faster than the first one!
The third method is a bit special. It is exclusive to SQL Server. Therefore, if you are not SQL Server, you cannot use this method. So please upgrade it! Experience the benefits of SQL server2008.
Insert into mytable (ID, name) values (7 ,'003'), (8 ,'004'), (9 ,'005')
-- EOF --
Author: xingbaifang
Web: http://xbf321.cnblogs.com/
Time: 2010.3.14