Tuesday, 7 June 2011

Inserting multiple record in one insert statement

CREATE TABLE [dbo].[employee]([empid] [varchar](10) NULL,[empname] [varchar](100) NULL,[salary] [int] NULL,[mgrid] [varchar]
)

There are following two ways.

1.
Insert into employee select 'E0001','RAM',25000,'E0002' Union all
select
'E0002','SHYAM',55000,'E0003'Union all
select
'E0003','RAMSHYAM',55000,''Union all
select


2.

Insert into employee select 'E0001','RAM',25000,'E0002' Insert into employee select 'E0002','SHYAM',55000,'E0003'Insert into employee select 'E0003','RAMSHYAM',55000,''Insert into employee select 'E0004','JOSHI',35000,'E0002'
'E0004','JOSHI',35000,'E0002'(10) NULL ON [PRIMARY]

No comments: