午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    sqlite快速入門指南
    來(lái)源:易賢網(wǎng) 閱讀:95944 次 日期:2016-11-14 16:32:40
    溫馨提示:易賢網(wǎng)小編為您整理了“sqlite快速入門指南”,方便廣大網(wǎng)友查閱!
    這篇文章主要介紹了sqlite快速入門指南,作為開(kāi)源的嵌入式數(shù)據(jù)庫(kù),sqlite可以在不需要過(guò)多投入數(shù)據(jù)庫(kù)開(kāi)發(fā)時(shí)提供十分輕便的服務(wù),需要的朋友可以參考下
     

    1. 介紹

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

    2. 安裝

    sqlite on windows

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

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

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

        注意: <build#> 是 sqlite 的編譯版本號(hào)

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

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

    •         sqlite-amalgamation-<build#>.zip

    sqlite on linux

    在 多個(gè) linux 發(fā)行版提供了方便的命令來(lái)獲取 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ù)庫(kù)

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

    sqlite3 test.db
    創(chuàng)建表:
     
    sqlite> create table mytable(id integer primary key, value text);
    該表包含一個(gè)名為 id 的主鍵字段和一個(gè)名為 value 的文本字段。

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

    接下來(lái)往表里中寫入一些數(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|micheal2|jenny3|francis4|kerk
    設(shè)置格式化查詢結(jié)果:
     
    sqlite> .mode column;sqlite> .header on;
    sqlite> select * from mytable;
    id     value----------- -------------1
    micheal2      jenny3      francis4      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ù)庫(kù)到 sql 文件:

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

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

    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ù)庫(kù):

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

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

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

     

    更多信息請(qǐng)查看技術(shù)文章
    易賢網(wǎng)手機(jī)網(wǎng)站地址:sqlite快速入門指南
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國(guó)考·省考課程試聽(tīng)報(bào)名

    • 報(bào)班類型
    • 姓名
    • 手機(jī)號(hào)
    • 驗(yàn)證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢 | 簡(jiǎn)要咨詢須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
    工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號(hào):hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報(bào)警專用圖標(biāo)