What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 29052 |  Welcome, Guest!   Register  Login
 Home > Interview Questions > SQL Server Interview Questions > How can you insert multiple rows togethe ...

How can you insert multiple rows together in a single insert statement for a table?

Interview question and answer by: Virendradugar | Posted on: 12/3/2009 | Category: SQL Server Interview questions | Views: 4442 |


Answer:

It is not possible to insert multiple rows with a single insert statement. If you want to insert multiple rows, one have to write multiple insert statements considering that you are working SQL server 2005 or it's below version.

But SQL Server 2008 allows to insert multiple rows with a single insert statement.

As for example,

In sql server 2005, if we need to insert multiple row, we used to do something like this.

CREATE TABLE [State] (

[StateID] int,
[StateName] VARCHAR(20)
)
GO

INSERT INTO State
VALUES (1, 'Gujarat')

INSERT INTO State
VALUES (2, 'Dehli')

INSERT INTO State
VALUES (3, 'Bihar')



But with SQL Server 2008 we can combine all the three insert statement in single insert statement. See below:

CREATE TABLE [State] (

[StateID] int,
[StateName] VARCHAR(20)
)
GO

INSERT INTO State
VALUES (1, 'Gujarat'),
(2, 'Dehli'),
(3, 'Bihar')


Hope this helps...

Asked In: Many Interviews | Alert Moderator 
Found interesting? Add this to:


 Responses

Posted by: Poster | Posted on: 03 Dec 2009 07:23:06 AM | Alert Moderator 

Thanks Virendra, can you give any example how to write multiple rows in SQL Server 2008?

Regards,

Posted by: Lakhangarg | Posted on: 03 Dec 2009 07:44:08 AM | Alert Moderator 

Hi Virendradugar -

it will be better if you can write any example of your above question. because we can insert multiple rows in using single insert statement using select statement.

Thanks & Regards
Lakhan Pal Garg

Posted by: Virendradugar | Posted on: 03 Dec 2009 08:17:29 AM | Alert Moderator 

Hi Poster and Lakhan Pal,

I have updated the answer with an example.

Hope this helps..

Thanks,
Virendra Dugar

>> Write Response - Respond to this post and get points

Even more ... | Submit Interview Questions and win prizes!

More Interview Questions from Virendradugar

Even more ... | Submit Interview Questions and win prizes!


About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/22/2013 4:32:30 AM