sqlite常用语法

在终端下运行sqlite3 <*.db>,出现如下提示符:
SQLite version 3.7.2
Enter “.help” for instructions
Enter SQL statements terminated with a “;”
sqlite>
<*.db> 是要打开的数据库文件。若该文件不存在,则自动创建。 
显示所有命令 
sqlite> .help
退出sqlite3
sqlite>.quit
显示当前打开的数据库文件 
sqlite>.database
显示数据库中所有表名 
sqlite>.tables
查看表的结构 
sqlite>.schema <table_name>
/*******************************************/ 
以下为SQL命令,每个命令以;结束 
创建新表 
>create table <table_name> (f1 type1, f2 type2,…);
sqlite> create table student(no integer primary key, name text, score real); 
删除表 
sqlite>drop table <table_name>
sqlite>drop table student 
查询表中所有记录 
sqlite>select * from <table_name>; 
按指定条件查询表中记录 
sqlite>select * from <table_name> where <expression>; 
sqlite> select * from student 
sqlite> select * from student where name=’zhao’
sqlite> select * from student where name=’zhao’ and score >=95
sqlite> select count(*) from student where score>90 
向表中添加新记录 
sqlite>insert into <table_name> values (value1, value2,…);
sqlite> insert into student values(1, ‘zhao’, 92); 
按指定条件删除表中记录 
sqlite>delete from <table_name> where <expression>
sqlite> delete from student where score<60; 
更新表中记录 
sqlite>update <table_name> set <f1=value1>, <f2=value2>… where <expression>; 
sqlite> update student set score=0;
sqlite> update student set name=’sun’ where no=3; 
在表中添加字段 
sqlite>alter table <table> add column <field> <type>; 
sqlite> alter table student add column gender integer default 0; 
在表中删除字段 
Sqlite中不允许删除字段,可以通过下面步骤达到同样的效果
sqlite> create table stu as select no, name, score from student
sqlite> drop table student
sqlite> alter table stu rename to student

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值