insert more than one row sql code example

Example 1: sql server insert multiple rows

INSERT INTO table_name (column_list)
VALUES
    (value_list_1),
    (value_list_2),
    ...
    (value_list_n);

Example 2: SQL Insert Multiple Rows

INSERT INTO StudentTable

( Rollo, Name, Class, Contact )

VALUES ( '1', 'Jonny', '10th', '9856245'  ),

( '2', 'Ronny', '12th', '5421545'  );

Example 3: insert more than 1000 rows sql

BEGIN TRY
BEGIN TRANSACTION
-- Please enter 1000 rows for each insert
INSERT INTO OFBC_MD20_CC_Values (Column1, Column2, Column3, Column4, Column5, Cloumn6, Column7)
values('data1','data2','data3','data4','data5','data6','data7'),('data1','data2','data3','data4','data5','data6','data7')...   -- Till max 1000 rows
INSERT INTO OFBC_MD20_CC_Values (Column1, Column2, Column3, Column4, Column5, Cloumn6, Column7)
values('data1','data2','data3','data4','data5','data6','data7'),('data1','data2','data3','data4','data5','data6','data7')...... -- Till max 1000
INSERT INTO OFta3','data4','data5','data6','dBC_MD20_CC_Values (Column1, Column2, Column3, Column4, Column5, Cloumn6, Column7)
values('data1','data2','daata7'),('data1','data2','data3','data4','data5','data6','data7')...... -- Till max 1000
......Many time as needed

 

COMMIT TRANSACTION
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
ROLLBACK TRAN -- RollBack in case of Error

DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY();

 

-- you can Raise ERROR with RAISEERROR() Statement including the details of the exception
THROW 51000, @ErrorMessage, 1
END CATCH

Tags:

Sql Example