精品丰满熟女一区二区三区_五月天亚洲欧美综合网_亚洲青青青在线观看_国产一区二区精选

  • <menu id="29e66"></menu>

    <bdo id="29e66"><mark id="29e66"><legend id="29e66"></legend></mark></bdo>

  • <pre id="29e66"><tt id="29e66"><rt id="29e66"></rt></tt></pre>

      <label id="29e66"></label><address id="29e66"><mark id="29e66"><strike id="29e66"></strike></mark></address>
      學習啦>學習電腦>操作系統(tǒng)>Linux教程>

      linux的sqlite命令

      時間: 佳洲1085 分享

        linux下的sqlite命令并不是經(jīng)常使用的命令,下面由學習啦小編為大家搜集整理了linux的sqlite命令的相關知識,希望對大家有幫助!

        linux的sqlite命令

        數(shù)據(jù)導入的來源可以是其他應用程序的輸出,也可以是指定的文本文件,這里采用指定的文本文件。

        1. 首先,確定導入的數(shù)據(jù)源,這里是待導入的,按固定格式的文本文件。

        2. 然后,依照導入的文件格式,確定想導入的目標數(shù)據(jù)表,這個數(shù)據(jù)表如果沒有,可以依照待導入的文本文件格式,創(chuàng)建一個相對應的數(shù)據(jù)表。

        3. 最后,執(zhí)行.import命令,將文本文件中數(shù)據(jù)導入數(shù)據(jù)表中。

        1. 數(shù)據(jù)源

        在/home/ywx/yu/sqlite/下,創(chuàng)建一個名為data.txt的文本文件,并輸入以下數(shù)據(jù),數(shù)據(jù)之間采用逗號隔開

        id,name,age,address,hobby

        1,tom,24,beijing,football

        2,liu,27,heibei,fotball

        3,jim,26,shandong,football

        4,han,28,beijing,football

        5,meng,25,beijing,tennis

        2. 目標數(shù)據(jù)表

        這里創(chuàng)建一張目標數(shù)據(jù)表,通過分析文本格式,這里需要3個字段,分別是id,name,age。但在數(shù)據(jù)類型選擇時存在一個問題,id和age在文本文件中是按字符型存儲的,而其實際在數(shù)據(jù)表中,最好要表示成整型,因此這里要涉及到一個字符型數(shù)據(jù)類型向整型數(shù)據(jù)類型轉換的問題。

        在創(chuàng)建表時,將id和age的類型定義為整型,進行強制轉換,如果在數(shù)據(jù)導入時,發(fā)現(xiàn)轉換失敗,可以將id和age類型改為文本型。

        ywx@ywx:~/yu/sqlite$ sqlite3 test.db

        SQLite version 3.7.7.1 2011-06-28 17:39:05

        Enter ".help" for instructions

        Enter SQL statements terminated with a ";"

        sqlite> create table data_txt_table(id char(10),name char(10),age char(10),address varchar(15),hobby varchar (15));

        sqlite>

        linux的sqlite命令用法——導入命令

        sqlite> .separator ","

        sqlite> .import data.txt data_txt_table

        sqlite> select * from data_txt_table;

        id,name,age,address,hobby

        1,tom,24,beijing,football

        2,liu,27,heibei,fotball

        3,jim,26,shandong,football

        4,han,28,beijing,football

        5,meng,25,beijing,tennis

        sqlite>

        這里需要注意一點,在數(shù)據(jù)導入之前,先要根據(jù)數(shù)據(jù)的具體分的格式,設置數(shù)據(jù)導入的間隔符,例如在文本數(shù)據(jù)中采用的是‘,’來間隔數(shù)據(jù),因此應先調(diào)用.seperator 設置‘,’ 為間隔符。

        linux的sqlite命令用法——查看命令

        .schema 命令來查看指定的數(shù)據(jù)表的結構

        sqlite> .schema data_txt_table

        CREATE TABLE data_txt_table(id char(10),name char(10),age char(10),address varchar(15),hobby varchar (15));

        sqlite>

        .tables 命令用來查看當前數(shù)據(jù)庫的所有數(shù)據(jù)表

        sqlite> .tables

        data_txt_table

        sqlite>

        databases 命令用來查看當前所有數(shù)據(jù)庫

        sqlite> .databases

        seq name file

        --- --------------- ----------------------------------------------------------

        0 main /home/ywx/yu/sqlite/test.db

        1 temp

        linux的sqlite命令用法——數(shù)據(jù)導出

        數(shù)據(jù)導出也是一個常用到的操作,可以將指定表中的數(shù)據(jù)導出成SQL腳本,供其他數(shù)據(jù)庫使用,還可以將指定的數(shù)據(jù)表中的數(shù)據(jù)完整定位到標準輸出,也可以將指定數(shù)據(jù)庫中的數(shù)據(jù)完整的導入到另一個指定數(shù)據(jù)庫等,

        1. 導出成指定的SQL腳本

        將sqlite中指定的數(shù)據(jù)表以SQL創(chuàng)建腳本的形式導出,具體命令

        ywx@ywx:~/yu/sqlite$ sqlite3 test.db

        SQLite version 3.7.7.1 2011-06-28 17:39:05

        Enter ".help" for instructions

        Enter SQL statements terminated with a ";"

        sqlite> .output data.sql

        sqlite> .dump

        sqlite>

        ywx@ywx:~/yu/sqlite$ ll

        總計 16

        drwxr-xr-x 2 ywx ywx 4096 2011-08-13 23:15 ./

        drwxr-xr-x 7 ywx ywx 4096 2011-08-13 20:53 ../

        -rw-r--r-- 1 ywx ywx 602 2011-08-13 23:17 data.sql

        -rw-r--r-- 1 ywx ywx 2048 2011-08-13 22:44 test.db

        2. 數(shù)據(jù)庫導出

        data.sql test.db

        ywx@ywx:~/yu/sqlite$ sqlite3 test.db ".dump" | sqlite3 test2.db

        ywx@ywx:~/yu/sqlite$ ll

        總計 20

        drwxr-xr-x 2 ywx ywx 4096 2011-08-13 23:20 ./

        drwxr-xr-x 7 ywx ywx 4096 2011-08-13 20:53 ../

        -rw-r--r-- 1 ywx ywx 602 2011-08-13 23:17 data.sql

        -rw-r--r-- 1 ywx ywx 2048 2011-08-13 23:20 test2.db

        -rw-r--r-- 1 ywx ywx 2048 2011-08-13 22:44 test.db

        3. 其他格式,如:htm格式輸出

        ywx@ywx:~/yu/sqlite$ sqlite3 -html test.db "select * from data_txt_table" > liu.htm

        ywx@ywx:~/yu/sqlite$ ls

        data.sql liu.htm test2.db test.db

      3632239