sqlite3增删改查,导入导出

一、创建表

创建一个 Student 表,其中包含 Id、Name、Age 等字段.
sqlite>
sqlite> CREATE TABLE Students(Id integer,Name text,age integer);
sqlite> .tables
Students
sqlite> .schema Students
CREATE TABLE Students(Id integer,Name text,age integer);
sqlite>

这样,一个 Students 表就被建立了,这回再运行 .tables 命令就有响应了,系统告诉我们数据库中现在有一个 Students 表, 运行 .schema 命令,返回了我们创建这个表的 SQL 命令

二、修改表

下面,将前面的 Students 表的名字改为 Teachers
sqlite>
sqlite> .tables
Students
sqlite> ALTER TABLE Students RENAME TO Teachers;
sqlite> .tables
Teachers
sqlite>

原来数据库中只有一个 Students 表,改名以后再运行 .tables 命令,发现 Students 表已经没了,现在变成了 Teachers 表。

改变 Teachers 表的结构,增加一个 Sex 列
sqlite>
sqlite> .schema Teachers
CREATE TABLE “Teachers”(Id integer,Name text,age integer);
sqlite> ALTER TABLE Teachers ADD COLUMN Sex text;
sqlite> .schema Teachers
CREATE TABLE “Teachers”(Id integer,Name text,age integer, Sex text);
sqlite>

三、删除表

将Teachers 表删除
sqlite>
sqlite> .tables
Teachers
sqlite> DROP TABLE Teachers;
sqlite> .tables
sqlite>

删除 Teachers 表后再运行 .tables 命令,发现数据库已经空了

四、导出

sqlite>.output mydb.sql
sqlite>.dump
sqlite>.output stdout

五、导入

sqlite>.read file.sql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值