自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

一個小時內(nèi)學習SQLite數(shù)據(jù)庫

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

1. 介紹

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

2. 安裝

SQLite on Windows

1)進入 SQL 下載頁面:http://www.sqlite.org/download.html

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

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

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

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

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

sqlite-amalgamation-<build#>.zip

SQLite on Linux

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

  1. /* For Debian or Ubuntu /*  
  2. $ sudo apt-get install sqlite3 sqlite3-dev  
  3.  
  4. /* For RedHat, CentOS, or Fedora/*  
  5. $ yum install SQLite3 sqlite3-dev 

SQLite on Mac OS X

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

3. 創(chuàng)建*** SQLite 數(shù)據(jù)庫

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

  1. sqlite3 test.db 

創(chuàng)建表:

  1. sqlite> create table mytable(id integer primary key, value text);  
  2. 2 columns were created.  

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

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

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

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

查詢數(shù)據(jù):

  1. sqlite> select * from test;  
  2. 1|Micheal  
  3. 2|Jenny  
  4. 3|Francis  
  5. 4|Kerk 

設(shè)置格式化查詢結(jié)果:

  1. sqlite> .mode column;  
  2. sqlite> .header on;  
  3. sqlite> select * from test;  
  4. id          value  
  5. ----------- -------------  
  6. 1           Micheal  
  7. 2           Jenny  
  8. 3           Francis  
  9. 4           Kerk 

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

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

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

創(chuàng)建視圖:

  1. sqlite> create view nameview as select * from mytable; 

創(chuàng)建索引:

  1. sqlite> create index test_idx on mytable(value); 

4. 一些有用的 SQLite 命令

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

  1. sqlite> .schema [table

獲取所有表和視圖:

  1. sqlite > .tables 

獲取指定表的索引列表:

  1. sqlite > .indices [table ] 

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

  1. sqlite > .output [filename ]  
  2. sqlite > .dump  
  3. sqlite > .output stdout 

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

  1. sqlite > .read [filename ] 

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

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

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

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

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

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

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

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

 

原文鏈接:http://www.oschina.net/question/12_53183

【編輯推薦】

  1. 優(yōu)化MySQL語句的十個建議
  2. 點評:巍然聳立的SQL Server 2012
  3. 11個重要的數(shù)據(jù)庫設(shè)計規(guī)則
  4. SQL Server 2008中增強的匯總技巧
  5. Twitter將開源其使用的MySQL
責任編輯:林師授 來源: OSCHINA
相關(guān)推薦

2011-07-20 13:40:00

SQLite數(shù)據(jù)庫查詢數(shù)據(jù)

2021-12-30 09:40:33

CentOS家庭實驗室Linux

2011-07-20 12:55:17

SQLite數(shù)據(jù)庫插入數(shù)據(jù)

2011-07-20 14:57:47

SQLite數(shù)據(jù)庫ORDER BYGROUP BY

2025-04-17 04:00:00

SQLite-WebSQLite數(shù)據(jù)庫

2011-07-20 13:18:01

SQLite數(shù)據(jù)庫修改和刪除數(shù)據(jù)

2016-11-14 16:37:44

2011-07-21 17:29:42

iPhone Sqlite 數(shù)據(jù)庫

2011-07-20 14:32:59

SQLite數(shù)據(jù)庫LIKE查詢IN集合查詢

2014-08-21 10:05:14

ZMapTCPIP

2011-07-20 12:34:49

SQLite數(shù)據(jù)庫約束

2019-08-15 07:00:54

SQLite數(shù)據(jù)庫內(nèi)存數(shù)據(jù)庫

2017-07-12 09:20:42

SQLite數(shù)據(jù)庫移植

2013-08-21 15:42:25

2021-05-14 10:45:21

PythonNoSQL數(shù)據(jù)庫

2011-06-01 10:59:59

Oceanbase海量數(shù)據(jù)庫

2017-05-18 12:16:03

LinuxPythonNoSql

2011-08-04 18:00:47

SQLite數(shù)據(jù)庫批量數(shù)據(jù)

2011-08-02 16:16:08

iPhone開發(fā) SQLite 數(shù)據(jù)庫

2024-10-28 16:31:03

點贊
收藏

51CTO技術(shù)棧公眾號