Search This Blog

Tuesday, August 28, 2012

Different method for insert data in Table (Row Value Constructor) SQL 2008


Different method for insert data in Table (Row Value Constructor) SQL 2008

In SQL Server table Insert, Delete and Update data as per Data Manipulation Language. We have insert large number of data in table by insert query.SQL Server 2008 provide new method for insert data in SQL tables.

CREATE TABLE [dbo].[test_table](
          [sno] [int] NOT NULL,
          [name] [nvarchar](50) NULL,
          [BILL] [nchar](10) NULL
) ON [PRIMARY]

GO

Method 1

Add 3 rows of data using a traditional ANSI insert SQL statement as shown below

insert into test_table (sno ,name ,BILL) values (1 , 'rohan' ,345)
insert into test_table (sno ,name ,BILL) values (2 , 'vipin' ,745)
insert into test_table (sno ,name ,BILL) values (3 , 'chandra' ,845)

(1 row(s) affected)

(1 row(s) affected)

(1 row(s) affected)

sno
name
BILL
1
rohan
345      
2
vipin
745      
3
chandra
845      

Method 2

insert into test_table select 4 , 'rohan1' ,345
insert into test_table select, 'vipin1' ,745
insert into test_table select, 'chandra1' ,845

(1 row(s) affected)

(1 row(s) affected)
(1 row(s) affected)

sno
name
BILL
1
rohan
345      
2
vipin
745      
3
chandra
845      
4
rohan1
345      
5
vipin1
745      
6
chandra1
845      

Method 3

Add 3 rows of data using INSERT SQL Statement with a SELECT and UNION clause to insert data.

insert into test_table
select 7 , 'rohan1' , 150000.00
union select 8 , 'ravi' , 250000.00
union select 9 , 'raj' ,120000.00

(3 row(s) affected)

sno
name
BILL
1
rohan
345      
2
vipin
745      
3
chandra
845      
4
rohan1
345      
5
vipin1
745      
6
chandra1
845      
7
rohan1
150000.00
8
ravi
250000.00
9
raj
120000.00

Method 4 (Row Value Constructor SQL 2008)

Add 3 rows of data using INSERT SQL Statement with a Row Value Constructor.

insert into test_table (sno ,name ,BILL) values
(10 , 'amit' , 150000.00),
(11 , 'nitin' , 250000.00),
(12 , 'cp' , 120000.00)

(3 row(s) affected)

sno
name
BILL
1
rohan
345      
2
vipin
745      
3
chandra
845      
4
rohan1
345      
5
vipin1
745      
6
chandra1
845      
7
rohan1
150000.00
8
ravi
250000.00
9
raj
120000.00
10
amit
150000.00
11
nitin
250000.00
12
cp
120000.00


No comments :