Linux下数据库sqlite3常用命令

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


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


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


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


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


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


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


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


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


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


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


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


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



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


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

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


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


例如:
alter table student rename to people;

你可能感兴趣的:(Linux下数据库sqlite3常用命令)