加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

mini2440上SQLite操作

发布时间:2020-12-12 20:22:47 所属栏目:百科 来源:网络整理
导读:(1)创建数据库文件test.db [root@mini2440 /]#cd /home/www #sqlite3 test.db SQLite version 3.7.7.1 2011-06-28 17:39:05 Enter ".help" for instructions Enter SQL statements terminated with a ";" sqlite (2)创建表 sqlite create table students(id

(1)创建数据库文件test.db
[root@mini2440 /]#cd /home/www
#sqlite3 test.db
SQLite version 3.7.7.1 2011-06-28 17:39:05
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>

(2)创建表
sqlite> create table students(id integer,name text,age integer);
sqlite> .tables
students
sqlite>

(3)删除表
sqlite> drop table students
sqlite> .tables
sqlite>

(4)查看表结构
sqlite> create table students(id integer,age integer);
sqlite> .schema students
CREATE TABLE students(id integer,age integer);
sqlite>

(5)插入列
sqlite> alter table students add cul;
sqlite> alter table students add column sex text;
sqlite> .schema students
CREATE TABLE students(id integer,age integer,cul,sex text);
sqlite>

(6)插入表记录
sqlite> insert into students values(1,'aa',10,'m');
sqlite> insert into students values(2,'bb',11,1,'f');
sqlite> select * from students;
1|aa|10|0|m
2|bb|11|1|f
sqlite>

(7)重命名表
sqlite> alter table students rename to stu;
sqlite>

(8)删除某一列,这为列cul
sqlite> begin transaction;
sqlite> create temporary table stu_bak(id integer,sex text);
sqlite> insert into stu_bak select id,name,age,sex from stu;
sqlite> drop table stu;
sqlite> create table stu(id integer,sex text);
sqlite> insert into stu select id,sex from stu_bak;
sqlite> drop table stu_bak;
sqlite> select * from stu;
1|aa|10|m
2|bb|11|f
sqlite> commit;
sqlite>

(9)退出程序
sqlite> .quit
[root@mini2440 www]#

本篇文章来源于 Linux公社网站(www.linuxidc.com) 原文链接:http://www.linuxidc.com/Linux/2012-02/54689.htm

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读