濮阳杆衣贸易有限公司

主頁 > 知識庫 > SQLite快速入門指南

SQLite快速入門指南

熱門標(biāo)簽:南昌呼叫中心外呼系統(tǒng)哪家好 簡單的智能語音電銷機(jī)器人 怎么去開發(fā)一個(gè)電銷機(jī)器人 怎么申請400熱線電話 泗洪正規(guī)電話機(jī)器人找哪家 湖南保險(xiǎn)智能外呼系統(tǒng)產(chǎn)品介紹 小程序智能電話機(jī)器人 ai電話電話機(jī)器人 河北便宜電銷機(jī)器人軟件

1. 介紹

SQLite 是一個(gè)開源的嵌入式關(guān)系數(shù)據(jù)庫,實(shí)現(xiàn)自包容、零配置、支持事務(wù)的SQL數(shù)據(jù)庫引擎。 其特點(diǎn)是高度便攜、使用方便、結(jié)構(gòu)緊湊、高效、可靠。 與其他數(shù)據(jù)庫管理系統(tǒng)不同,SQLite 的安裝和運(yùn)行非常簡單,在大多數(shù)情況下 - 只要確保SQLite的二進(jìn)制文件存在即可開始創(chuàng)建、連接和使用數(shù)據(jù)庫。如果您正在尋找一個(gè)嵌入式數(shù)據(jù)庫項(xiàng)目或解決方案,SQLite是絕對值得考慮。

2. 安裝

SQLite on Windows

    進(jìn)入 SQL 下載頁面:http://www.sqlite.org/download.html

    下載 Windows 下的預(yù)編譯二進(jìn)制文件包:

  •         sqlite-shell-win32-x86-build#>.zip
  •         sqlite-dll-win32-x86-build#>.zip

    注意: build#> 是 sqlite 的編譯版本號

    將 zip 文件解壓到你的磁盤,并將解壓后的目錄添加到系統(tǒng)的 PATH 變量中,以方便在命令行中執(zhí)行 sqlite 命令。

    可選: 如果你計(jì)劃發(fā)布基于 sqlite 數(shù)據(jù)庫的應(yīng)用程序,你還需要下載源碼以便編譯和利用其 API

  •         sqlite-amalgamation-build#>.zip

SQLite on Linux

在 多個(gè) Linux 發(fā)行版提供了方便的命令來獲取 SQLite:
 

/* For Debian or Ubuntu /*
$ sudo apt-get install sqlite3 sqlite3-dev
 
/* For RedHat, CentOS, or Fedora/*
$ yum install SQLite3 sqlite3-dev

SQLite on Mac OS X

如果你正在使用 Mac OS 雪豹或者更新版本的系統(tǒng),那么系統(tǒng)上已經(jīng)裝有 SQLite 了。


3. 創(chuàng)建首個(gè) SQLite 數(shù)據(jù)庫

現(xiàn)在你已經(jīng)安裝了 SQLite 數(shù)據(jù)庫,接下來我們創(chuàng)建首個(gè)數(shù)據(jù)庫。在命令行窗口中輸入如下命令來創(chuàng)建一個(gè)名為  test.db 的數(shù)據(jù)庫。
 

sqlite3 test.db

創(chuàng)建表:
 
sqlite> create table mytable(id integer primary key, value text);

該表包含一個(gè)名為 id 的主鍵字段和一個(gè)名為 value 的文本字段。

注意: 最少必須為新建的數(shù)據(jù)庫創(chuàng)建一個(gè)表或者視圖,這么才能將數(shù)據(jù)庫保存到磁盤中,否則數(shù)據(jù)庫不會被創(chuàng)建。

接下來往表里中寫入一些數(shù)據(jù):
 

sqlite> insert into mytable(id, value) values(1, 'Micheal');
sqlite> insert into mytable(id, value) values(2, 'Jenny');
sqlite> insert into mytable(value) values('Francis');
sqlite> insert into mytable(value) values('Kerk');

查詢數(shù)據(jù):
 
sqlite> select * from mytable;
1|Micheal
2|Jenny
3|Francis
4|Kerk

設(shè)置格式化查詢結(jié)果:
 
sqlite> .mode column;
sqlite> .header on;
sqlite> select * from mytable;
id     value
----------- -------------
1      Micheal
2      Jenny
3      Francis
4      Kerk

.mode column 將設(shè)置為列顯示模式,.header 將顯示列名。

修改表結(jié)構(gòu),增加列:
 

sqlite> alter table mytable add column email text not null '' collate nocase;;

創(chuàng)建視圖:
 
sqlite> create view nameview as select * from mytable;

創(chuàng)建索引:
 
sqlite> create index test_idx on mytable(value);


4. 一些有用的 SQLite 命令

顯示表結(jié)構(gòu):

sqlite> .schema [table]

獲取所有表和視圖:

sqlite > .tables 

獲取指定表的索引列表:

sqlite > .indices [table ]

導(dǎo)出數(shù)據(jù)庫到 SQL 文件:

sqlite > .output [filename ] 
sqlite > .dump 
sqlite > .output stdout

從 SQL 文件導(dǎo)入數(shù)據(jù)庫:

sqlite > .read [filename ]

格式化輸出數(shù)據(jù)到 CSV 格式:

sqlite >.output [filename.csv ] 
sqlite >.separator , 
sqlite > select * from test; 
sqlite >.output stdout

從 CSV 文件導(dǎo)入數(shù)據(jù)到表中:

sqlite >create table newtable ( id integer primary key, value text ); 
sqlite >.import [filename.csv ] newtable 

備份數(shù)據(jù)庫:

/* usage: sqlite3 [database] .dump > [filename] */
sqlite3 mytable.db .dump > backup.sql

恢復(fù)數(shù)據(jù)庫:

/* usage: sqlite3 [database ]  [filename ] */ 
sqlite3 mytable.db  backup.sql

您可能感興趣的文章:
  • 詳解SQLite中的數(shù)據(jù)類型
  • 詳解SQLite中的查詢規(guī)劃器
  • 簡單分析SQLite4的一些設(shè)計(jì)改變

標(biāo)簽:柳州 那曲 景德鎮(zhèn) 荊門 瀘州 江蘇 淮安 威海

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《SQLite快速入門指南》,本文關(guān)鍵詞  SQLite,快速,入門,指南,SQLite,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《SQLite快速入門指南》相關(guān)的同類信息!
  • 本頁收集關(guān)于SQLite快速入門指南的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    外汇| 越西县| 武清区| 安义县| 当阳市| 青河县| 隆回县| 平原县| 寿阳县| 克东县| 昌黎县| 青川县| 嘉义县| 永川市| 确山县| 青龙| 正阳县| 密云县| 大洼县| 武义县| 沙洋县| 南阳市| 雅安市| 崇文区| 裕民县| 东乌| 岚皋县| 呈贡县| 昌黎县| 高尔夫| 钟山县| 漯河市| 绥德县| 庄浪县| 黑河市| 香格里拉县| 牟定县| 周宁县| 天长市| 景洪市| 阳朔县|