首页 > 代码库 > 一次性插入多条记录快的不只一点点

一次性插入多条记录快的不只一点点

最近在做性能优化,系统中有很多log信息,看了看SQLServer的执行结果分析log,发现log占了不少的时间,于是想如果log合并到一起一次性进行多条log的输入工作时间将减少很多。于是就做了一下的一个小实验,证明猜测是正确的,暂时没有去深究SQLServer是如何做的,如果有大神有此方面的研究部分拿出来分享下。

DECLARE @SMSTime INT,@CMSTime INTSELECT @CMSTime=DATEPART(ms,GETDATE())BEGININSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_1, test_011, test111_01_1, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_2, test_012, test111_01_2, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_3, test_013, test111_01_3, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_4, test_014, test111_01_4, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_5, test_015, test111_01_5, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_6, test_016, test111_01_6, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_7, test_017, test111_01_7, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_8, test_018, test111_01_8, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_9, test_019, test111_01_9, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_10, test_0110, test111_01_10, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_11, test_0111, test111_01_11, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_12, test_0112, test111_01_12, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_13, test_0113, test111_01_13, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_14, test_0114, test111_01_14, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_15, test_0115, test111_01_15, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_16, test_0116, test111_01_16, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_17, test_0117, test111_01_17, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_18, test_0118, test111_01_18, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_19, test_0119, test111_01_19, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_20, test_0120, test111_01_20, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_21, test_0121, test111_01_21, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_22, test_0122, test111_01_22, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_23, test_0123, test111_01_23, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_24, test_0124, test111_01_24, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_25, test_0125, test111_01_25, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_26, test_0126, test111_01_26, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_27, test_0127, test111_01_27, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_28, test_0128, test111_01_28, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_29, test_0129, test111_01_29, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_30, test_0130, test111_01_30, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_31, test_0131, test111_01_31, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_32, test_0132, test111_01_32, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_33, test_0133, test111_01_33, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_34, test_0134, test111_01_34, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_35, test_0135, test111_01_35, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_36, test_0136, test111_01_36, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_37, test_0137, test111_01_37, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_38, test_0138, test111_01_38, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_39, test_0139, test111_01_39, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_40, test_0140, test111_01_40, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_41, test_0141, test111_01_41, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_42, test_0142, test111_01_42, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_43, test_0143, test111_01_43, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_44, test_0144, test111_01_44, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_45, test_0145, test111_01_45, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_46, test_0146, test111_01_46, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_47, test_0147, test111_01_47, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_48, test_0148, test111_01_48, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_49, test_0149, test111_01_49, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_50, test_0150, test111_01_50, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_51, test_0151, test111_01_51, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_52, test_0152, test111_01_52, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_53, test_0153, test111_01_53, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_54, test_0154, test111_01_54, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_55, test_0155, test111_01_55, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_56, test_0156, test111_01_56, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_57, test_0157, test111_01_57, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_58, test_0158, test111_01_58, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_59, test_0159, test111_01_59, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_60, test_0160, test111_01_60, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_61, test_0161, test111_01_61, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_62, test_0162, test111_01_62, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_63, test_0163, test111_01_63, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_64, test_0164, test111_01_64, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_65, test_0165, test111_01_65, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_66, test_0166, test111_01_66, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_67, test_0167, test111_01_67, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_68, test_0168, test111_01_68, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_69, test_0169, test111_01_69, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_70, test_0170, test111_01_70, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_71, test_0171, test111_01_71, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_72, test_0172, test111_01_72, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_73, test_0173, test111_01_73, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_74, test_0174, test111_01_74, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_75, test_0175, test111_01_75, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_76, test_0176, test111_01_76, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_77, test_0177, test111_01_77, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_78, test_0178, test111_01_78, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_79, test_0179, test111_01_79, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_80, test_0180, test111_01_80, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_81, test_0181, test111_01_81, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_82, test_0182, test111_01_82, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_83, test_0183, test111_01_83, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_84, test_0184, test111_01_84, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_85, test_0185, test111_01_85, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_86, test_0186, test111_01_86, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_87, test_0187, test111_01_87, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_88, test_0188, test111_01_88, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_89, test_0189, test111_01_89, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_90, test_0190, test111_01_90, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_91, test_0191, test111_01_91, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_92, test_0192, test111_01_92, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_93, test_0193, test111_01_93, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_94, test_0194, test111_01_94, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_95, test_0195, test111_01_95, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_96, test_0196, test111_01_96, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_97, test_0197, test111_01_97, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_98, test_0198, test111_01_98, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_99, test_0199, test111_01_99, GETDATE() )INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES (MarkTest_01_100, test_01100, test111_01_100, GETDATE() )ENDSELECT @SMSTime=DATEPART(ms,GETDATE())-@CMSTimePRINT Insert 100 lines separelly cost time: +CONVERT(VARCHAR,@SMSTime)SELECT @CMSTime=DATEPART(ms,GETDATE())INSERT INTO System_TempVar (Session_ID, Var_Name, Var_Value, EntryDate ) VALUES(MarkTest_02_1, test_02_1, test111_02_1, GETDATE() ),(MarkTest_02_2, test_02_2, test111_02_2, GETDATE() ),(MarkTest_02_3, test_02_3, test111_02_3, GETDATE() ),(MarkTest_02_4, test_02_4, test111_02_4, GETDATE() ),(MarkTest_02_5, test_02_5, test111_02_5, GETDATE() ),(MarkTest_02_6, test_02_6, test111_02_6, GETDATE() ),(MarkTest_02_7, test_02_7, test111_02_7, GETDATE() ),(MarkTest_02_8, test_02_8, test111_02_8, GETDATE() ),(MarkTest_02_9, test_02_9, test111_02_9, GETDATE() ),(MarkTest_02_10, test_02_10, test111_02_10, GETDATE() ),(MarkTest_02_11, test_02_11, test111_02_11, GETDATE() ),(MarkTest_02_12, test_02_12, test111_02_12, GETDATE() ),(MarkTest_02_13, test_02_13, test111_02_13, GETDATE() ),(MarkTest_02_14, test_02_14, test111_02_14, GETDATE() ),(MarkTest_02_15, test_02_15, test111_02_15, GETDATE() ),(MarkTest_02_16, test_02_16, test111_02_16, GETDATE() ),(MarkTest_02_17, test_02_17, test111_02_17, GETDATE() ),(MarkTest_02_18, test_02_18, test111_02_18, GETDATE() ),(MarkTest_02_19, test_02_19, test111_02_19, GETDATE() ),(MarkTest_02_20, test_02_20, test111_02_20, GETDATE() ),(MarkTest_02_21, test_02_21, test111_02_21, GETDATE() ),(MarkTest_02_22, test_02_22, test111_02_22, GETDATE() ),(MarkTest_02_23, test_02_23, test111_02_23, GETDATE() ),(MarkTest_02_24, test_02_24, test111_02_24, GETDATE() ),(MarkTest_02_25, test_02_25, test111_02_25, GETDATE() ),(MarkTest_02_26, test_02_26, test111_02_26, GETDATE() ),(MarkTest_02_27, test_02_27, test111_02_27, GETDATE() ),(MarkTest_02_28, test_02_28, test111_02_28, GETDATE() ),(MarkTest_02_29, test_02_29, test111_02_29, GETDATE() ),(MarkTest_02_30, test_02_30, test111_02_30, GETDATE() ),(MarkTest_02_31, test_02_31, test111_02_31, GETDATE() ),(MarkTest_02_32, test_02_32, test111_02_32, GETDATE() ),(MarkTest_02_33, test_02_33, test111_02_33, GETDATE() ),(MarkTest_02_34, test_02_34, test111_02_34, GETDATE() ),(MarkTest_02_35, test_02_35, test111_02_35, GETDATE() ),(MarkTest_02_36, test_02_36, test111_02_36, GETDATE() ),(MarkTest_02_37, test_02_37, test111_02_37, GETDATE() ),(MarkTest_02_38, test_02_38, test111_02_38, GETDATE() ),(MarkTest_02_39, test_02_39, test111_02_39, GETDATE() ),(MarkTest_02_40, test_02_40, test111_02_40, GETDATE() ),(MarkTest_02_41, test_02_41, test111_02_41, GETDATE() ),(MarkTest_02_42, test_02_42, test111_02_42, GETDATE() ),(MarkTest_02_43, test_02_43, test111_02_43, GETDATE() ),(MarkTest_02_44, test_02_44, test111_02_44, GETDATE() ),(MarkTest_02_45, test_02_45, test111_02_45, GETDATE() ),(MarkTest_02_46, test_02_46, test111_02_46, GETDATE() ),(MarkTest_02_47, test_02_47, test111_02_47, GETDATE() ),(MarkTest_02_48, test_02_48, test111_02_48, GETDATE() ),(MarkTest_02_49, test_02_49, test111_02_49, GETDATE() ),(MarkTest_02_50, test_02_50, test111_02_50, GETDATE() ),(MarkTest_02_51, test_02_51, test111_02_51, GETDATE() ),(MarkTest_02_52, test_02_52, test111_02_52, GETDATE() ),(MarkTest_02_53, test_02_53, test111_02_53, GETDATE() ),(MarkTest_02_54, test_02_54, test111_02_54, GETDATE() ),(MarkTest_02_55, test_02_55, test111_02_55, GETDATE() ),(MarkTest_02_56, test_02_56, test111_02_56, GETDATE() ),(MarkTest_02_57, test_02_57, test111_02_57, GETDATE() ),(MarkTest_02_58, test_02_58, test111_02_58, GETDATE() ),(MarkTest_02_59, test_02_59, test111_02_59, GETDATE() ),(MarkTest_02_60, test_02_60, test111_02_60, GETDATE() ),(MarkTest_02_61, test_02_61, test111_02_61, GETDATE() ),(MarkTest_02_62, test_02_62, test111_02_62, GETDATE() ),(MarkTest_02_63, test_02_63, test111_02_63, GETDATE() ),(MarkTest_02_64, test_02_64, test111_02_64, GETDATE() ),(MarkTest_02_65, test_02_65, test111_02_65, GETDATE() ),(MarkTest_02_66, test_02_66, test111_02_66, GETDATE() ),(MarkTest_02_67, test_02_67, test111_02_67, GETDATE() ),(MarkTest_02_68, test_02_68, test111_02_68, GETDATE() ),(MarkTest_02_69, test_02_69, test111_02_69, GETDATE() ),(MarkTest_02_70, test_02_70, test111_02_70, GETDATE() ),(MarkTest_02_71, test_02_71, test111_02_71, GETDATE() ),(MarkTest_02_72, test_02_72, test111_02_72, GETDATE() ),(MarkTest_02_73, test_02_73, test111_02_73, GETDATE() ),(MarkTest_02_74, test_02_74, test111_02_74, GETDATE() ),(MarkTest_02_75, test_02_75, test111_02_75, GETDATE() ),(MarkTest_02_76, test_02_76, test111_02_76, GETDATE() ),(MarkTest_02_77, test_02_77, test111_02_77, GETDATE() ),(MarkTest_02_78, test_02_78, test111_02_78, GETDATE() ),(MarkTest_02_79, test_02_79, test111_02_79, GETDATE() ),(MarkTest_02_80, test_02_80, test111_02_80, GETDATE() ),(MarkTest_02_81, test_02_81, test111_02_81, GETDATE() ),(MarkTest_02_82, test_02_82, test111_02_82, GETDATE() ),(MarkTest_02_83, test_02_83, test111_02_83, GETDATE() ),(MarkTest_02_84, test_02_84, test111_02_84, GETDATE() ),(MarkTest_02_85, test_02_85, test111_02_85, GETDATE() ),(MarkTest_02_86, test_02_86, test111_02_86, GETDATE() ),(MarkTest_02_87, test_02_87, test111_02_87, GETDATE() ),(MarkTest_02_88, test_02_88, test111_02_88, GETDATE() ),(MarkTest_02_89, test_02_89, test111_02_89, GETDATE() ),(MarkTest_02_90, test_02_90, test111_02_90, GETDATE() ),(MarkTest_02_91, test_02_91, test111_02_91, GETDATE() ),(MarkTest_02_92, test_02_92, test111_02_92, GETDATE() ),(MarkTest_02_93, test_02_93, test111_02_93, GETDATE() ),(MarkTest_02_94, test_02_94, test111_02_94, GETDATE() ),(MarkTest_02_95, test_02_95, test111_02_95, GETDATE() ),(MarkTest_02_96, test_02_96, test111_02_96, GETDATE() ),(MarkTest_02_97, test_02_97, test111_02_97, GETDATE() ),(MarkTest_02_98, test_02_98, test111_02_98, GETDATE() ),(MarkTest_02_99, test_02_99, test111_02_99, GETDATE() ),(MarkTest_02_100, test_02_100, test111_02_100, GETDATE() )SELECT @SMSTime=DATEPART(ms,GETDATE())-@CMSTimePRINT Insert 100 lines in batch cost time: +CONVERT(VARCHAR,@SMSTime)
View Code

 

测试数据是一样的,分开执行和一起执行的结果是一样的

(1 行受影响)
......
(1 行受影响)

(1 行受影响)
Insert 100 lines separelly cost time: 40

(100 行受影响)
Insert 100 lines in batch cost time: 10

速度快不少吧,这个在做log的时候可以进行优化。

 

一次性插入多条记录快的不只一点点