How To Insert Multiple Rows with One INSERT Statement in MS SQL Server?
Submitted by: AdministratorIf you want to insert multiple rows with a single INSERT statement, you can use a subquery instead of the VALUES clause. Rows returned from the subquery will be inserted the target table. The following tutorial exercise gives you a good example:
INSERT INTO ggl_links SELECT id+500, REVERSE(url),
notes, counts, created FROM ggl_links
GO
(3 row(s) affected)
SELECT * FROM ggl_links
GO
id url notes counts created
101 www.globalguideline.com NULL 0 2006-04-30
102 www.globalguideline.com/html NULL 0 2007-05-19
103 www.globalguideline.com/sql NULL NULL 2007-05-19
601 www.globalguideline.com/seo NULL 0 2006-04-30
602 www.globalguideline.com/xml NULL 0 2007-05-19
603 www.globalguideline.com/JavaScript_Guide NULL NULL 2007-05-19
As you can see, "INSERT INTO ... SELECT ..." is powerful statement. you can use it build up data in tables quickly.
Submitted by: Administrator
INSERT INTO ggl_links SELECT id+500, REVERSE(url),
notes, counts, created FROM ggl_links
GO
(3 row(s) affected)
SELECT * FROM ggl_links
GO
id url notes counts created
101 www.globalguideline.com NULL 0 2006-04-30
102 www.globalguideline.com/html NULL 0 2007-05-19
103 www.globalguideline.com/sql NULL NULL 2007-05-19
601 www.globalguideline.com/seo NULL 0 2006-04-30
602 www.globalguideline.com/xml NULL 0 2007-05-19
603 www.globalguideline.com/JavaScript_Guide NULL NULL 2007-05-19
As you can see, "INSERT INTO ... SELECT ..." is powerful statement. you can use it build up data in tables quickly.
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Select Some Specific Rows from a Table in MS SQL Server? |
☺ | What Happens If You Insert a Duplicate Key for the Primary Key Column in MS SQL Server? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | PHP MSSQL - How To Display a Past Time in Days, Hours and Minutes? |
☺ | How to Create a View using Data from Another View? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Sybase Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |