Introduction:
This article explains how to insert multiple rows into table with single insert query in sql server or sql server insert multiple records in table with one insert statement with example.
To insert multiple rows into table with single insert query in sql server we can follow different methods like as shown below
Method- 1:
Example
Method- 2:
Example
Output:
This article explains how to insert multiple rows into table with single insert query in sql server or sql server insert multiple records in table with one insert statement with example.
To insert multiple rows into table with single insert query in sql server we can follow different methods like as shown below
Method- 1:
insert into @sampletable(id,name,education) values(val1,val2,val3), (val4,val5,val6), (val7,val8,val9)
Example
declare @sampletable table(id int,name varchar(50),education varchar(50)) insert into @sampletable(id,name,education) values(1,'Tom','MCA'), (2,'Shaim','MBA'), (3,'Jack','B.Tech') select * from @sampletable
Method- 2:
insert into @table1(id,name,education) select val1,val2,val3 union all select val4,val5,val6 union all select val7,val8,val9
Example
declare @sampletable table(id int,name varchar(50),education varchar(50)) insert into @sampletable(id,name,education) select 1,'Tom','MCA' union all select 2,'Shaim','MBA' union all select 3,'Jack','B.Tech' select * from @sampletable
Output:
No comments:
Post a Comment