赞
踩
场景一:修改不存在外键约束的多个数据表
UPDATE 数据表1 别名,数据表2 别名
SET 数据表1.列名 = 数据值,数据表2.列名 = 数据值
WHERE 条件语句【必须写入表之间的逻辑关系】
UPDATE student s1,studentquery s2
SET s1.studentname = '张er',s1.studentpassword = '145263',
s2.studentage = 24,s2.studentlocal = '大腿',s2.studentphone = '1456'
where s1.studentid = s2.studentid and s1.studentid = 1813004526;
步骤一:在数据库连接文件打开批量操作,否者报 BadSqlGrammarException 错误
allowMultiQueries=true
步骤二:编写批量操作语句
UPDATE SET 数据表一.字段名 = 值 WHERE 子句;
UPDATE SET 数据表二.字段名 = 值 WHERE 子句;
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/db.nuc?useSSL=true&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true
jdbc.username=root
jdbc.password=root
UPDATE SET student.studentid= 1813004860 WHERE studentname = '李四';
UPDATE SET studentquery.studentid= 1813004860 WHERE studentclass = '18';
场景二:修改存在外键约束的多个数据表
UPDATE 数据表1 别名
LEFT JOIN 数据表2 别名 ON 外键约束关系
SET 数据表1.列名 = 数据值,数据表2.列名 = 数据值
where 条件语句
UPDATE student s1
LEFT JOIN studentquery s2 ON s1.studentid=s2.studentid
SET s1.studentname = '张a',s1.studentpassword = '145263',
s2.studentage = 2,s2.studentlocal = '大腿',s2.studentphone = '1456'
where s1.studentid=s2.studentid and s1.studentid = 1813004526;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。