sql 书写 规范 优化

  

规范 做注解  便于修改和优化  规范


  
    
    

    .......

  

  sql片段(多次使用的sql 语句 减少多次重复)个人认为

使用sql

  
    
  

1.INESRT 

  a.一般的添加


  insert into 表名(ID, CompanyId, UserId,
  ......
  )
  values (#{id,jdbcType=INTEGER}, #{companyid,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER},
  ......
  )    // jdbcType=INTEGER    jdbcType=VARCHAR  jdbcType=TIMESTAMP  jdbcType=DOUBLE

   b.批量添加

  
  insert into 表名
  
  
  ID,
  

  
  CompanyId,
  

  
  UserId,
  

  
  TradeName,
  

  ......
  

  
  
  #{id,jdbcType=INTEGER},
  

  
  #{companyid,jdbcType=INTEGER},
  

  
  #{userid,jdbcType=INTEGER},
  

  
  #{tradename,jdbcType=VARCHAR},
  

  ...................
  
  

  

2.DELETE  

  
    delete from 表名
    where ID = #{id,jdbcType=INTEGER}
  

3.UPDATE 

  
  update AccountDetail
  set ID = #{record.id,jdbcType=INTEGER},
  CompanyId = #{record.companyid,jdbcType=INTEGER},
  UserId = #{record.userid,jdbcType=INTEGER},
  TradeName = #{record.tradename,jdbcType=VARCHAR},
  .....
  

  

  
    update AccountDetail
    
    
      CompanyId = #{companyid,jdbcType=INTEGER},
    

    
      UserId = #{userid,jdbcType=INTEGER},
    

      ....
    

    where ID = #{id,jdbcType=INTEGER}
  

4.SELECT

 

 

一些简单的用法 

  1.  trim   select trim ("           a            ") 结果 a  去除 前后空

  2.  sql 书写 规范 优化_第1张图片

 

 

 

 

 




















and ${criterion.condition}



and ${criterion.condition} #{criterion.value}



and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}



and ${criterion.condition}

#{listItem}




















and ${criterion.condition}


and ${criterion.condition} #{criterion.value}


and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}


and ${criterion.condition}

#{listItem}











id, name, price, color, cima, imgPath








delete from g_good
where id = #{id,jdbcType=INTEGER}



delete from g_good






insert into g_good (id, name, price,
color, cima, imgPath
)
values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{price,jdbcType=INTEGER},
#{color,jdbcType=VARCHAR}, #{cima,jdbcType=VARCHAR}, #{imgpath,jdbcType=VARCHAR}
)



insert into g_good


id,


name,


price,


color,


cima,


imgPath,




#{id,jdbcType=INTEGER},


#{name,jdbcType=VARCHAR},


#{price,jdbcType=INTEGER},


#{color,jdbcType=VARCHAR},


#{cima,jdbcType=VARCHAR},


#{imgpath,jdbcType=VARCHAR},







update g_good


id = #{record.id,jdbcType=INTEGER},


name = #{record.name,jdbcType=VARCHAR},


price = #{record.price,jdbcType=INTEGER},


color = #{record.color,jdbcType=VARCHAR},


cima = #{record.cima,jdbcType=VARCHAR},


imgPath = #{record.imgpath,jdbcType=VARCHAR},








update g_good
set id = #{record.id,jdbcType=INTEGER},
name = #{record.name,jdbcType=VARCHAR},
price = #{record.price,jdbcType=INTEGER},
color = #{record.color,jdbcType=VARCHAR},
cima = #{record.cima,jdbcType=VARCHAR},
imgPath = #{record.imgpath,jdbcType=VARCHAR}






update g_good


name = #{name,jdbcType=VARCHAR},


price = #{price,jdbcType=INTEGER},


color = #{color,jdbcType=VARCHAR},


cima = #{cima,jdbcType=VARCHAR},


imgPath = #{imgpath,jdbcType=VARCHAR},


where id = #{id,jdbcType=INTEGER}



update g_good
set name = #{name,jdbcType=VARCHAR},
price = #{price,jdbcType=INTEGER},
color = #{color,jdbcType=VARCHAR},
cima = #{cima,jdbcType=VARCHAR},
imgPath = #{imgpath,jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}

 

 

 

关于优化

  1.

 

  ........

转载于:https://www.cnblogs.com/gzl180110/p/10557504.html

你可能感兴趣的:(sql 书写 规范 优化)