数据库的插入更新语句
来源:互联网 发布:淘宝海外物流怎么发货 编辑:程序博客网 时间:2024/05/18 00:24
目的:实现在数据库插入数据的时候,只对重复的数据进行更新;
实现方式:
1、在表中建立一个唯一索引,主键(已有唯一索引的特性)
2、在插入数据 sql语句:insert into table_name( 列名1,列名2)values(。。。)on duplicate key update 列名=values(值)或者(值)
这样子在出现于 唯一索引的值相同情况下 就会之更新其中的数据!
用例:
insert into tb_mx_baopantest
(
serv_node_name,
not_report,
reported,
not_cancel,
cancelled,
part_dealed,
dealed,
part_cancelled,
abolished,
beReport,
reporting,
date,
time
) values('1235',3,3,3,3,3,3,3,3,3,3,3,3)
ON DUPLICATE KEY UPDATE
not_report=VALUES(not_report),
reported=VALUES(reported),
not_cancel=VALUES(not_cancel),
cancelled=VALUES(cancelled),
part_dealed=VALUES(part_dealed),
dealed=VALUES(dealed),
part_cancelled=VALUES(part_cancelled),
abolished=VALUES(abolished),
beReport=VALUES(beReport),
reporting=VALUES(reporting),
date=VALUES(date),
time=VALUES(time);
例子:
http://blog.csdn.net/lalaguozhe/article/details/9150049
阅读全文
0 0
- 数据库的插入更新语句
- 数据库操作:添加、插入、更新语句
- 数据库操作:添加、插入、更新语句
- 数据库操作:添加、插入、更新语句
- 数据库操作:添加、插入、更新语句
- mysql数据库中关于记录存在,更新记录,记录不存在,插入记录的sql语句编写
- mysql批量插入,更新的sql语句
- access数据库的更新语句!
- mysql数据库中创建、删除、更新、插入数据、等语句
- struct中dao连接数据库插入更新语句
- Oracle数据库学习3之修改、插入、更新语句
- SQL更新插入语句
- 数据库中表的插入、更新、删除
- 经典的利用插入Asp数据库插入语句
- ds更新、插入数据库
- php数据库插入语句
- 数据库.插入语句
- 数据库添加插入语句
- 每天一个 Linux 命令(33):df 命令
- C
- io流分类
- SSH复用代码最终版
- 4071: [Apio2015]巴邻旁之桥
- 数据库的插入更新语句
- scrapy使用手册
- 11、U-boot编译及下载
- C语言算法
- 2017.5.14测试 第4题: 解码
- Python groupby,聚合,分组级运算
- WatchService监控文件变化
- oracle创建表空间和授权
- stylus入门使用方法