sqlserver insert statement

// - create a transaction 
the Create  PROC  [ dbo ] . [ Proc_XXXXX ]    
@xxx  VARCHAR ( 50 )
 AS 
BEGIN 
BEGIN  TRAN 
BEGIN TRY 
    ..................... insert 
    COMMIT  TRAN  
the END TRY 

the BEGIN the CATCH
     the SELECT ERROR_MESSAGE ()
     ROLLBACK  TRAN 
the END the CATCH
 the END 
the GO
Insert one million data
 use Test
 the DECLARE  @i  the INT 
SET  @i = 0 ;
 the DECLARE  @id  the INT 
the SET  @id = 0 
the WHILE  @i < 1000000       - 100W to insert the number you want to execute 
the BEGIN 
the INSERT  the INTO table_2 (ID)   - xx is the name of the table 
the VALUES   ( @i + . 1 ) 
 the SET  @i = @i + . 1 
the END 
inserted one million data 2 
the DECLARE  @LN  VARCHAR ( 300 ), @MN VARCHAR ( 200 ), @FN  VARCHAR ( 200 )
 DECLARE  @LN_N  INT , @MN_N  INT , @FN_N  INT 
the SET  @LN = ' Li Zhang, Liu Wang, Chen Yang Huang Chao Zhou Wu Xu Zhu Ma Hu Guolin He Gaoliang Sun Zheng Luo Han Tang Song Xie Hui Deng Xiao Cao Feng had Chengcaipengpan Yuanyudongyu sage Lv Wei Jiang Tian Shen Jiang Fan Jiangfu Daoudine bell Luwangdaicui Renlu Liao Yao Fang Jinqiu Tan Wei Jia Xia Zou Shi Xiongmeng Qinyanxuehou Leibai Long Duanhaokongshao history Maochangwangu Laiwu Kang Ho Yan Yin Qian Shi Hong cattle Gong ' 
the sET  @MN = ' de Shaozong Bang Chang Yu Fu charitable world Yiwei Xiao Xu set following the Friends of Phoenix Taisho Kai Shi Zhongyuan Kui home life must be executed first Yuan-Ze Insein any artificial tree cutting wind in Xiuwen Tan Chui would like to light ' 
the SET  @FN = ' Li Lei Yunfeng bright macro red magnanimity Liang Liang Liang Liang seven grain flag Qi Qi Mou Mou Mi Mi meters dense Lei Lei rib class celebrate love Qing Qing Xing Xing Xing punishment ' 
the SET  @LN_N = LEN ( @LN )
SET @MN_N=LEN(@MN)
SET @FN_N=LEN(@FN)
DECLARE @TMP VARCHAR(1000),@I INT
SET @I=1
WHILE @I<=1000000
BEGIN
    SET @TMP=CAST(SUBSTRING(@LN,CAST(RAND()*@LN_N AS INT),1) AS VARCHAR)
    SET @TMP=@TMP+CAST(SUBSTRING(@MN,CAST(RAND()*@MN_N AS INT),1) AS VARCHAR)
    SET @TMP=@TMP+CAST(SUBSTRING(@FN,CAST(RAND()*@FN_N AS INT),1) AS VARCHAR)
    INSERT INTO student(sname)VALUES(@TMP)
    SET @I=@I+1
END
If the presence of the insert
 use Test
 INSERT  INTO Table_1 (A, B) 
 SELECT   ' B ' , ' B ' 
WHERE  Not  EXISTS ( SELECT  *  from Table_1 WHERE A = ' B ' )   - the first query in the insertion - to return the affected row
Unconsciously inseparable 2018 - 09 - 28  11 : 18 : 07 

IF  not  EXISTS ( the SELECT  *  from xxxss the WHERE xxx = 1 ) 
 the begin 
  ................. // insert statement
 End 
Go 

 

Guess you like

Origin www.cnblogs.com/enych/p/11926824.html