Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4214063
  • 博文数量: 1148
  • 博客积分: 25453
  • 博客等级: 上将
  • 技术积分: 11949
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-06 21:14
文章分类

全部博文(1148)

文章存档

2012年(15)

2011年(1078)

2010年(58)

分类: SQLite/嵌入式数据库

2011-08-13 21:51:21

操作, 建库、建表、插入数据、修改数据、删除数据、删除表、删除库

1. 建库
   在/home/ywx/yu 下输入 sqlite test.db ,便可以在当前目录线下创建一个文件名为test.db的数据库文件
  1. root@ywx:/home/ywx/yu/sqlite# sqlite3 test.db
  2. SQLite version 3.7.7.1 2011-06-28 17:39:05
  3. Enter ".help" for instructions
  4. Enter SQL statements terminated with a ";"
  5. sqlite> .database
  6. seq name file
  7. --- --------------- ----------------------------------------------------------
  8. 0 main /home/ywx/yu/sqlite/test.db
  9. sqlite> .quit
  10. root@ywx:/home/ywx/yu/sqlite# ll
  11. 总计 1720
  12. drwxr-xr-x 3 ywx ywx 4096 2011-08-13 22:09 ./
  13. drwxr-xr-x 7 ywx ywx 4096 2011-08-13 20:53 ../
  14. -rw-r--r-- 1 root root 0 2011-08-13 22:09 test.db

2. 建表
  1. root@ywx:/home/ywx/yu/sqlite# sqlite3 test.db
  2. SQLite version 3.7.7.1 2011-06-28 17:39:05
  3. Enter ".help" for instructions
  4. Enter SQL statements terminated with a ";"
  5. sqlite> create table infor(name varchar(10),age int);
  6. sqlite>


3. 插入数据
  1. sqlite> insert into infor values ('liu',23);
  2. sqlite> insert into infor values ('tom',21);
  3. sqlite> insert into infor values ('jim',20);
  4. sqlite> insert into infor values ('han',18);
  5. sqlite> insert into infor values ('meng',3);
  查看添加的记录
  1. sqlite> select * from infor;
  2. liu|23
  3. tom|21
  4. jim|20
  5. han|18
  6. meng|3

4.删除数据
  1. sqlite> delete from infor where name like 'han';
  2. sqlite> select * from infor;
  3. liu|23
  4. tom|21
  5. jim|20
  6. meng|3

5. 更新数据

  1. sqlite> update infor set age=24 where name = 'meng';
  2. sqlite> select * from infor;
  3. liu|23
  4. tom|21
  5. jim|20
  6. meng|24

6. 查看表与库信息

  1. sqlite> .tables
  2. infor
  3. sqlite> .database
  4. seq name file
  5. --- --------------- ----------------------------------------------------------
  6. 0 main /home/ywx/yu/sqlite/test.db
  7. 1 temp

7. 删除表

  1. sqlite> drop table infor;
  2. sqlite> .tables
  3. sqlite>

8. 删除库
  1. root@ywx:/home/ywx/yu/sqlite# rm test.db

阅读(1632) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~