SQLite資料庫的掛接及常用命令(轉自:http://blog.csdn.net/windone0109/article/details/5514948)

來源:互聯網
上載者:User

安裝:

官方網站下載最新的sqlite版本

官方網站: http://www.sqlite.org/

為: http://www.sqlite.org/download.html

官方的下載頁面提供了很多版本的下載…這裡介紹一下;

Source Code: 原始碼版本的下載

Documentation:  相關文檔

Precompiled Binaries for Linux / Precompiled Binaries For Mac OS X /

Precompiled Binaries For Windows

Linux/Mac/Win版本的先行編譯版本


如果你只是資料庫的使用者那麼下載已經編譯好的版本即可! 這裡我是Win使用者,下載的檔案為: sqlite3.exe

將這個檔案放到一個目錄中,這樣就完成了全部的sqlite資料庫的安裝!

 

建立:

在命令提示字元下($為shell提示號), 測試的sqlite3.exe路徑為e:/sqlite3/sqlite3.exe

網上也提供了很多方法,但好象都有點問題,經過摸索結論為以下幾種方法,但不確定是否受作業系統系統影響!

產生資料庫檔案後掛接 
$> sqlite3.exe test.db ;

$> sqlite3.exe test.db

直接掛接產生

$> sqlite3.exe test.db;

選擇性掛接 挑選已經存在的資料檔案掛接 
$> sqlite3.exe test.db 或者

$> sqlite3.exe e:/sqlite3/test.db

掛接好資料庫後,就可以通過命令列的形式對所掛接的資料庫操作了!


   Cmd 進入命令列
   1)
   建立資料庫檔案:
   >SQLite3 d:/test.db 斷行符號
   就產生了一個test.db在d盤。
   這樣同時也SQLite3掛上了這個test.db

   2) 
   用.help可以看看有什麼命令
   >.help 斷行符號即可

   3)可以在這裡直接輸入SQL語句建立表格 用;結束,然後斷行符號就可以看到了

   4)看看有建立了多少表
   >.tables

   5)看錶結構
   >.schema 表名

   6)看看目前掛的資料庫
   >.database

   7)如果要把查詢輸出到檔案
   >.output 檔案名稱
   > 查詢語句;
   查詢結果就輸出到了檔案c:/query.txt 
   把查詢結果用螢幕輸出
   >.output stdout


   8)把表結構輸出,同時索引也會輸出
     .dump 表名
   9)退出
   >.exit 或者.quit

 

sqlite官方協助提示資訊:

sqlite> .help.help.bail ON|OFF           Stop after hitting an error.  Default OFF.databases             List names and files of attached databases.dump ?TABLE? ...      Dump the database in an SQL text format.echo ON|OFF           Turn command echo on or off.exit                  Exit this program.explain ON|OFF        Turn output mode suitable for EXPLAIN on or off..header(s) ON|OFF      Turn display of headers on or off.help                  Show this message.import FILE TABLE     Import data from FILE into TABLE.indices TABLE         Show names of all indices on TABLE.load FILE ?ENTRY?     Load an extension library.mode MODE ?TABLE?     Set output mode where MODE is one of:                         csv      Comma-separated values                         column   Left-aligned columns.  (See .width)                         html     HTML <table> code                         insert   SQL insert statements for TABLE                         line     One value per line                         list     Values delimited by .separator string                         tabs     Tab-separated values                         tcl      TCL list elements.nullvalue STRING      Print STRING in place of NULL values.output FILENAME       Send output to FILENAME.output stdout         Send output to the screen.prompt MAIN CONTINUE  Replace the standard prompts.quit                  Exit this program.read FILENAME         Execute SQL in FILENAME.schema ?TABLE?        Show the CREATE statements.separator STRING      Change separator used by output mode and .import.show                  Show the current values for various settings.tables ?PATTERN?      List names of tables matching a LIKE pattern.timeout MS            Try opening locked tables for MS milliseconds.timer ON|OFF          Turn the CPU timer measurement on or off.width NUM NUM ...     Set column widths for "column" mode

 

 

它支援大部分的SQL命令,這是一個列表:

  • ATTACH DATABASE
  • BEGIN TRANSACTION
  • comment
  • COMMIT TRANSACTION
  • COPY
  • CREATE INDEX
  • CREATE TABLE
  • CREATE TRIGGER
  • CREATE VIEW
  • DELETE
  • DETACH DATABASE
  • DROP INDEX
  • DROP TABLE
  • DROP TRIGGER
  • DROP VIEW
  • END TRANSACTION
  • EXPLAIN
  • expression
  • INSERT
  • ON CONFLICT clause
  • PRAGMA
  • REPLACE
  • ROLLBACK TRANSACTION
  • SELECT
  • UPDATE 

    它還提供了虛擬機器用於處理sql語句,這是一個很有趣的東西。支援事務功能。

  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.