1.表不存在则创建

create table  if not exists student( _id Integer primary key autoincrement , name Text , age Integer)


2.当表中的数据不存在时插入数据

insert into student(name,age) select 'zz7zz7zz',25 where not exists(select * from student where name='zz7zz7zz' and age=25)

重复执行多次,仍然只有一条数据


3.当表中的数据不存在则插入,存在则更新 (使用REPLACE  语句)

这时候的创建表的sql语句为:create table  if not exists student( _id Integer primary key , name Text , age Integer)

不存在插入,存在更新sql语句为:replace into student( _id , name ,age ) VALUES ( 1,'zz7zz7zz',25) ,重复执行多次,仍然只有一条数据


将年龄改为35,发现数据表没有插入新数据,只是更新了

replace into student( _id , name ,age ) VALUES ( 1,'zz7zz7zz',35)


将学生id(主键)改为2,则发现插入了一条新数据

replace into student( _id , name ,age ) VALUES ( 2,'zz7zz7zz',35)



引用文章: http://www.cnblogs.com/liping13599168/archive/2011/05/24/2054908.html


   

邮箱:zz7zz7zz@163.com

微博 :http://weibo.com/u/3209971935

更多相关文章

  1. “罗永浩抖音首秀”销售数据的可视化大屏是怎么做出来的呢?
  2. Nginx系列教程(三)| 一文带你读懂Nginx的负载均衡
  3. 不吹不黑!GitHub 上帮助人们学习编码的 12 个资源,错过血亏...
  4. Android(安卓)检测SD卡是否可用
  5. targetSdkVersion导致的Android运行时权限问题
  6. Android中的四大组件回顾
  7. android 调用系统相机拍照,并保存到SD卡
  8. 移动数据流程
  9. 2014.07.23(2) ——— android FragmentPagerAdapter的notifyDataS

随机推荐

  1. 如何知道php脚本中的名称是指mysql表还是
  2. 获取特定行的索引
  3. Jsp+javaBean+mysql的网络云盘
  4. SQLSTATE [HY000] [2002]没有这样的文件
  5. Mysql数据库存储引擎
  6. mysql中文乱码彻底解决
  7. 远程连接Linux虚拟机上的mysql失败的解决
  8. MySQL 主从同步Out of Memory 错误分析
  9. MySQL数据库8(二十)视图
  10. CentOS7安装MySQL5.7遇到的若干问题记录