SQLlite下载以及简单使用

发布于:2025-07-18 ⋅ 阅读:(23) ⋅ 点赞:(0)

SQLite Download Page

cd D:\WK\2025\StudentManagerSystem\sqlite
D:
entManagerSystem\sqlite>sqlite3.exe 所建库的名字.db

一:命令
<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


创建表:            create  table 表名(元素名 类型,…);

删除表:            drop  table 表名;             

插入数据:       insert  into 表名 values(, , ,) ;  

创建索引:       create [unique] index 索引名on 表名(col….);

删除索引:   drop index 索引名(索引是不可更改的,想更改必须删除重新建)
删除数据:       delete from 表名;             

更新数据:       update 表名 set 字段=’修改后的内容’ where 条件;

增加一个列:  Alter table 表名 add column 字段 数据类型; 

选择查询:       select 字段(以”,”隔开) from 表名 where 条件;

日期和时间: Select datetime('now')

日期:   select date('now');       
时间:  select time('now');  

总数:select count(*) from table1;
求和:select sum(field1) from table1;
平均:select avg(field1) from table1;
最大:select max(field1) from table1;
最小:select min(field1) from table1;

排序:select 字段 from table1 order by 字段(desc或asc)  ;(降序或升序)

分组:select 字段 from table1 group by 字段,字段…  ;

限制输出:select 字段fromtable1 limit x offset y;

                          = select 字段 from table1 limit y , x;

(备注:跳过y行,取x行数据)
PRAGMA encoding;   检查数据库编码
PRAGMA encoding;   检查数据库编码
PRAGMA integrity_check;  检查数据库是否损坏 ok则没损坏

网站公告

今日签到

点亮在社区的每一天
去签到