4.表数据的操作-insert、delete
2015-09-09 21:25
459 查看
1.插入数据
insert...values:插入一行数据
insert...set:可以指定插入行中某些列的值,注意非空字段必须赋值
insert...select:插入其他表数据,注意主键不能重复
replace:针对primary key或者unique key有重复的情况,insert无法插入,3中语法同insert
包含:replace...values/replace...set/replace...select
注意:在插入前将表中冲突的记录删除,再插入新记录
2.删除数据
delete:一行行删除
delete table1, table2 from table1,table2 where table1.id=table2.id
或者:delete from table1, table2 using table1,table2 where table1.id=table2.id
示例:删除表1中在表2里不存在的记录:
DELETE t1 FROM table1 t1 LEFT JOIN table2 t2 ON t1.id=t2,id WHERE t2.id IS NULL
truncate:速度比delete快,先删除表再建立新表
truncate tablename
3.修改数据 --update
修改单个表:
update tablename set tname='' where ...
修改多个表:
update table1,table2 set t1='...',t2='...' where table1.id=table2.id
来自为知笔记(Wiz)
insert...values:插入一行数据
insert...set:可以指定插入行中某些列的值,注意非空字段必须赋值
insert...select:插入其他表数据,注意主键不能重复
replace:针对primary key或者unique key有重复的情况,insert无法插入,3中语法同insert
包含:replace...values/replace...set/replace...select
注意:在插入前将表中冲突的记录删除,再插入新记录
2.删除数据
delete:一行行删除
delete table1, table2 from table1,table2 where table1.id=table2.id
或者:delete from table1, table2 using table1,table2 where table1.id=table2.id
示例:删除表1中在表2里不存在的记录:
DELETE t1 FROM table1 t1 LEFT JOIN table2 t2 ON t1.id=t2,id WHERE t2.id IS NULL
truncate:速度比delete快,先删除表再建立新表
truncate tablename
3.修改数据 --update
修改单个表:
update tablename set tname='' where ...
修改多个表:
update table1,table2 set t1='...',t2='...' where table1.id=table2.id
来自为知笔记(Wiz)
相关文章推荐
- 蓝懿iOS培训日志7 控件学习
- [分布式系统]-分布式消息系统:Kafka
- 系统调用原理
- 0909Android基础安卓四大组件之Service
- AdaultBird--我的黑马程序员之路!Chapter2---异常体系,多线程,同步代码块和同步函数,死锁
- 阿里又起社交心,天天动听做音乐轻社交?
- 字符串加密
- 动态面板——自动幻灯片
- Minimum Depth of Binary Tree
- 老生常谈:everything is object
- UVALive 4670 Dominating Patterns (AC自动机)
- vi编辑器的使用(2)
- 南阳oj 棋盘覆盖 题目45
- AOP入门一
- vi编辑器的使用(1)
- 菜鸟级springmvc+spring+mybatis整合开发用户登录功能(下)
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
- CodeForces 551E GukiZ and GukiZiana
- nyoj 17 数据结构 最长单调递增子序列
- R语言_安装包