码迷,mamicode.com
首页 > 数据库 > 详细

数据库的增删改查和使用流程

时间:2014-07-08 18:47:19      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:数据库   sqlite   流程   

创建表                      列名 类型,
1...create table Student (id integer , name text, sex text, age  integer)

2…create table  if not exists Student  (id integer , name text default ‘张三‘ , sex text not null, age  integer)

删除表       表名
drop table Student

插入
全部列插入       表名              值               
insert into Student values (1, ‘张三’, ’男’, 18)
部分列插入
insert into Student (name, sex) values ( ‘lisi‘, ‘nv‘)

主键 (唯一, 不能重复)
create table Student (id integer primary key,name text, age integer, sex text )

查询
所有数据
select * from Student
查询姓名这一列 / 两列
select name from Student
select name, sex from Student
条件查询
select * from Student where age > 10
select * from Student where age > 10 and sex = ‘nv‘
select * from Student where age between 15 and 20

升序/降序
select * from Student order by id sac / desc
只要前 5 条
select * from Student order by id asc limit 5

修改
1列
update Student set age = 18 where sex = ‘男’
多列(勿忘逗号分隔)
update Student set age = 16 , sex = ‘男‘  where age < 19

删除
数据
delete from Student where sex = ‘男‘
全部
delete from Student

使用sqlite
1.打开数据库
2.执行sql,做出数据处理
3.关闭数据库

操作
1.打开数据库
2.创建一个数据操作指针 stmt
3.执行sql 语句
4.处理结果

数据库的增删改查和使用流程,布布扣,bubuko.com

数据库的增删改查和使用流程

标签:数据库   sqlite   流程   

原文地址:http://blog.csdn.net/ysh1251685564/article/details/37507019

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!