Linux下数据库sqlite3常用命令

在Linux下使用sqlite3,要先安装好,不然无法使用。


特点:
1.数据库(database)文件的后缀为xx.db
2.数据库相关命令都是以.开头。


------------以下使用的people和student是我们制定的表的名字,不是命令名-------------------------


一:命令
<1>打开某个数据库文件中
sqlite3  test.db


<2>查看所有的命令介绍(英文)
.help


<3>退出当前数据库系统
.quit


<4>显示当前打开的数据库文的位置
.database


在当前的数据库文件中创建一张新表(语句) [注:以;结尾,<>中是我们可变的内容]
create table <table_name>(表头信息1,表头信息2,表头信息3...);


例如:
create table people(NAME,SEX,AGE);


<5>显示数据库中所有的表名
sqlite>.tables


<6>查看表中表头的信息
.schema


<7>显示调整成列模式
    sqlite> .mode column
          
<8>显示表头
    sqlite> .header on




二:语句
特点:
1-对大小写不敏感,以";"结尾
2-采用动态的数据类型,类型直接使用,系统会自动识别
3-数字可以直接填写,字符串需要用单引号引用起来,'string'。
 再字符串中若是需要使用单引号,两个单引号代表一个单引号
 o'clcok ====>'o''clock'


<1>创建一张新表  
在当前的数据库文件中创建一张新表(语句) [注:以;结尾,<>中是我们可变的内容]
create table <table_name>(表头信息1,表头信息2,表头信息3...);


例如:
create table people(NAME,SEX,AGE);


<2> 删除一张表
drop table <table_name>
例如:drop table people;


<3>向表中添加新的记录
insert into <table_name> values(value1,value2);
例如:insert into pople values(1,'a',20);


<4>查询表中所有的信息
select * from <table_name>;
例如:select * from people;


<5>向表中删除新纪录
delete from <table_name> where <expression>;
例如:delete form people where age=30;



<6>按指定的条件查询表中的记录
select * from <tables_name> where <expression>;


例如:
select * from people where ID = 4;
select * from people order by age asc;  //升序
select * from people order by age desc; //降序

<7>更新表中的记录
update <table_name> set <f1=value1>,<f2=value2>...where<expression>;
例如:
//把表中name=‘b’和age = 30的id重置为2;
udpate people set id=2 where name='b' and age='30';


<8>在表中添加字段(添加一列)
alter table <table_name> add column <file>;
例如:
//添加年龄一项
alter table people add column age;
//重命名新表
alter table <old_table> rename to <new_table>;


例如:
alter table student rename to people;
  • 5
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值