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則沒損壞