GVKun编程网logo

mssql sql高效关联子查询的update 批量更新(sql关联查询怎么提高速度)

1

本文将分享mssqlsql高效关联子查询的update批量更新的详细内容,并且还将对sql关联查询怎么提高速度进行详尽解释,此外,我们还将为大家带来关于(批量更新)对多个符合条件的id做更新操作、12

本文将分享mssql sql高效关联子查询的update 批量更新的详细内容,并且还将对sql关联查询怎么提高速度进行详尽解释,此外,我们还将为大家带来关于(批量更新)对多个符合条件的id做更新操作、125.mybaties 批量操作 批量新增 批量更新 批量删除 批量根据 id 查询、ansible 批量更新 filebeat 配置文件、ansible 批量更新 nginx 配置,以及失败时的自动回滚样例的相关知识,希望对你有所帮助。

本文目录一览:

mssql sql高效关联子查询的update 批量更新(sql关联查询怎么提高速度)

mssql sql高效关联子查询的update 批量更新(sql关联查询怎么提高速度)

mssql sql高效关联子查询的update 批量更新

mssql sql高效关联子查询的update 批量更新
/*
使用带关联子查询的Update更新 
  --1.创建测试表  
 

create TABLE Table1    (    a varchar(10),    b varchar(10),    c varchar(10),    CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED    (    a ASC    )    ) ON [PRIMARY]    create TABLE Table2    (    a varchar(10),    c varchar(10),    CONSTRAINT [PK_Table2] PRIMARY KEY CLUSTERED    (    a ASC    )    ) ON [PRIMARY]    GO    --2.创建测试数据    Insert into Table1 values(''赵'',''asds'',null)    Insert into Table1 values(''钱'',''asds'',''100'')    Insert into Table1 values(''孙'',''asds'',''80'')    Insert into Table1 values(''李'',''asds'',null)    Insert into Table2 values(''赵'',''90'')    Insert into Table2 values(''钱'',''100'')    Insert into Table2 values(''孙'',''80'')    Insert into Table2 values(''李'',''95'')    GO    select * from Table1    --3.通过Update方式更新    Update Table1 set c = (select c from Table2 where a = Table1.a) where c is null    GO    --4.显示更新后的结果    select * from Table1    GO    --5.删除测试表    drop TABLE Table1    drop TABLE Table2

(批量更新)对多个符合条件的id做更新操作

(批量更新)对多个符合条件的id做更新操作

需求描述:把checkbox勾选的对应id的记录的标志位置1或0,这个其实不难的,不过我自己做的话,肯定是多次访问数据库做更新,看了老大的代码,发现差距不是一般的大,老大把sql灵活运用,结果一次访问数据库,就做完更新了,真的是get到了。不多说,贴代码。

代码:

public void changeHide(String resIds, String type) throws Exception {//service层  type就是一个值 0 或 1
if(Tools.notEmpty(resIds)){
List<String> list = new ArrayList<>();
String[] resIdArr = resIds.split(",");
for (String resId :resIdArr) {
list.add(resId);
}
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("resIds",list);
paramMap.put("type",type);
dao.update("XXXXXResourcesMapper.changeHide",paramMap);
}
}
mapper里的sql:
<update id="changeHide" parameterType="java.util.Map">
update
<include refid="tableName"></include>
set r.hide = #{type}
where r.res_id in
<foreach item="item" index="index" collection="resIds" open="(" separator="," close=")">//这里要说明一下,collection参数一定要填写对应好,因为前边方法传的是resIds,所以这里也是,item表示list里的元素的别名 index表示索引,当指针来理解
#{item}
</foreach>
</update>

 

总结:这个批量更新的精华就在于,只要数据库中的id在这个list(也就是resIds)中存在,就对其进行更新操作。  让我拿来做,我可能会对resIds做个增强for循环,然后再循环里边调用update方法,参数就是每一个resId。还是敲得代码少,老大这个是真的厉害!!!

 

125.mybaties 批量操作 批量新增 批量更新 批量删除 批量根据 id 查询

125.mybaties 批量操作 批量新增 批量更新 批量删除 批量根据 id 查询

1. 效果

 

 

 

 

 

2. 代码 sql

 

<!--1.批量新增-->
<insert id="batchInsert" parameterType="java.util.List">
    insert into t_user (username,hobby,workage)
    values
    <foreach collection ="list" item="user" index= "index"
             separator =",">
        (#{user.username},#{user.hobby},#{user.workage})
    </foreach >
</insert>

 

 

<!-- 2.1 批量更新单个字段    优化方法 https://www.cnblogs.com/javalanger/p/10899088.html  -->
<update id="updateSingleData" parameterType="java.util.List">
      <foreach collection="list" item="user" index="index" separator=";">
          update t_user
          <set>
              <if test="user.hobby != null and user.hobby != ''''" >
                   hobby = #{user.hobby}
              </if>
          </set>
          where username = #{user.username}
      </foreach>
  </update>

  <!--3.批量更新多个字段 -->
  <update id="updateMoreData" parameterType="java.util.List">
      update t_user
      <trim prefix="set" suffixOverrides=",">

          <trim prefix="hobby =case" suffix="end,">
              <foreach collection="list" item="i" index="index">
                  <if test="i.hobby!=null">
                      when username=#{i.username} then #{i.hobby}
                  </if>
              </foreach>
          </trim>

          <trim prefix="workage =case" suffix="end,">
              <foreach collection="list" item="i" index="index">
                  <if test="i.workage!=null">
                      when username=#{i.username} then #{i.workage}
                  </if>
              </foreach>
          </trim>

      </trim>
      where

      <foreach collection="list" separator="or" item="i" index="index" >
          username=#{i.username}
      </foreach>


  </update>

 

<!-- 批量查询 -->
<select id="batchSelect"
        resultType="cn.ma.ddddd.domain.User2">
    select
    *
    from t_user where  username in
    <foreach collection="list" item="username" open="(" close=")" separator=",">
        #{username}
    </foreach>

</select>

 

 

<!-- 批量删除 -->
<delete id="batchDel">
    delete
    from t_user where  username in
    <foreach collection="list" item="username" open="(" close=")" separator=",">
        #{username}
    </foreach>

</delete>

 

3. mapper 接口类 及实体类

 

 

 

 

 

 

 

ansible 批量更新 filebeat 配置文件

ansible 批量更新 filebeat 配置文件

一、filebeat 准备工作:
1、prod-tomcat 为生产组,使用 ansible -ping 可以通
2、生成 filebeat 配置文件
3、如果执行不成功 ,注意双引号单引号替换


二、下发替换配置文件
ansible prod-tomcat -S -R root -m copy -a ''src=/etc/ansible/file/filebeat.yml dest=/etc/elk/filebeat/filebeat.yml mode=600 owner=root group=root''
三、kill 掉 filebeat 进程
ansible prod-tomcat -S -R root -m shell -a ''pkill filebeat''
四、后台启动 filebeat 进程
ansible task -m shell -a “chdir=/usr/local/filebeat nohup ./filebeat -e -c filebeat.yml > /dev/null 2>&1 &”
五、查看后台进程
ansible prod-tomcat -S -R root -m shell -a ''ps aux | grep filebeat | grep -v grep''






ansible 批量更新 nginx 配置,以及失败时的自动回滚样例

ansible 批量更新 nginx 配置,以及失败时的自动回滚样例

作者:weixin_34092455   https://blog.csdn.net/weixin_34092455/article/details/89733396

 

本文基于 ansible 2.3.0.0 编写

我们目前有 8 个大区共 24 台 Nginx 服务器,每个区除了 upstream 地址不同,其它配置参数都一样。自从使用了 ansible 来维护更新后,工作变得非常轻松,几分钟内就可以更新所有 24 台服务器的 Nginx 配置。并且实现了检查配置有误后,自动恢复上一次配置的机制。

以下就以此为例,展示如何利用 ansible 在自动化部署 Nginx 时,如何规避错误的配置。

首先看看我的 Nginx role 目录结构

  1.   deploy.Nginx/
  2.   ├── files
  3.   │ └── Nginx.conf
  4.   ├── handlers
  5.   │ └── main.yml
  6.   ├── tasks
  7.   │ ├── Debian.yml
  8.   │ ├── main.yml
  9.   │ └── sites_conf_test.yml
  10.   └── templates
  11.   ├── cms_console_newtouch_com.j2
  12.   └── console_newtouch_com.j2

roles/deploy.Nginx/tasks/main.yml 里 include sites_conf_test.yml 的代码片段:

  1.   - include: sites_conf_test.yml
  2.   vars:
  3.   - file: ''{{ item }}''
  4.   with_items:
  5.   - ''console_newtouch_com''

这里传递了变量 file 的值给 sites_conf_test.yml,这样我们可以扩展配置多个站点配置文件。


roles/deploy.Nginx/tasks/sites_conf_test.yml 的代码:

  1.   - name: Create ~/''{{ file }}.conf''
  2.   template:
  3.   src: ''../templates/{{ file }}.j2''
  4.   dest: ''~/{{ file }}.conf''
  5.   register: createResult
  6.    
  7.   - block:
  8.   - name: copy ''~/{{ file }}.conf''
  9.   copy:
  10.   src: ''~/{{ file }}.conf''
  11.   dest: ''/etc/Nginx/sites-enabled/{{ file }}.conf''
  12.   backup: yes
  13.   remote_src: yes
  14.   register: copyResult
  15.   when: createResult.changed
  16.   - name: ''Test {{ file }}.conf config''
  17.   command: Nginx -t
  18.   notify: Reload Nginx service
  19.   when: copyResult.changed
  20.   rescue:
  21.   - name: ''{{ file }}.conf test Failed, rolling backup file.''
  22.   copy:
  23.   src: ''{{ copyResult.backup_file }}''
  24.   dest: ''/etc/Nginx/sites-enabled/{{ file }}.conf''
  25.   remote_src: yes

代码解析:

  1. 首先使用 template 模块,在服务器上生成 Nginx 站点的配置文件。
  2. 2.3.0.0 有个问题还没解决,就是 template 模块的 backup 参数,并不会返回备份文件的名称,所以只能曲线救国,先创建一个临时的文件。
  3. 然后,重点就在这个 block 编排里。第一个 task 是把生成的 console_newtouch_com.conf 文件拷贝到 /etc/Nginx/sites-enabled/ 目录下,因为启用了 backup 参数,所以 copyResult 会包含 backup_file 的绝对路径地址名称。这个就用在配置回滚操作中。
  4. 第二个 task 就是执行 Nginx -t 来确认新配置文件是否正确了。如果失败了,就会触发 rescue 里的任务。我们只需要把备份文件恢复,保证服务器上的配置是好的。

同理可以用在更新 Nginx.conf 的操作里。

总结

以上是小编为你收集整理的ansible 批量更新 nginx 配置,以及失败时的自动回滚样例全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

原文地址:https://www.cnblogs.com/cheyunhua/p/14627140.html

关于mssql sql高效关联子查询的update 批量更新sql关联查询怎么提高速度的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于(批量更新)对多个符合条件的id做更新操作、125.mybaties 批量操作 批量新增 批量更新 批量删除 批量根据 id 查询、ansible 批量更新 filebeat 配置文件、ansible 批量更新 nginx 配置,以及失败时的自动回滚样例等相关知识的信息别忘了在本站进行查找喔。

本文标签: