SQLiteのコマンド一覧
SQLite3
コマンド一覧
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
sqlite> .help .archive ... Manage SQL archives .auth ON|OFF Show authorizer callbacks .backup ?DB? FILE Backup DB (default "main") to FILE .bail on|off Stop after hitting an error. Default OFF .binary on|off Turn binary output on or off. Default OFF .cd DIRECTORY Change the working directory to DIRECTORY .changes on|off Show number of rows changed by SQL .check GLOB Fail if output since .testcase does not match .clone NEWDB Clone data into NEWDB from the existing database .databases List names and files of attached databases .dbconfig ?op? ?val? List or change sqlite3_db_config() options .dbinfo ?DB? Show status information about the database .dump ?TABLE? ... Render all database content as SQL .echo on|off Turn command echo on or off .eqp on|off|full|... Enable or disable automatic EXPLAIN QUERY PLAN .excel Display the output of next command in a spreadsheet .exit ?CODE? Exit this program with return-code CODE .expert EXPERIMENTAL. Suggest indexes for specified queries .filectrl CMD ... Run various sqlite3_file_control() operations .fullschema ?--indent? Show schema and the content of sqlite_stat tables .headers on|off Turn display of headers on or off .help ?-all? ?PATTERN? Show help text for PATTERN .import FILE TABLE Import data from FILE into TABLE .imposter INDEX TABLE Create imposter table TABLE on index INDEX .indexes ?TABLE? Show names of indexes .limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT .lint OPTIONS Report potential schema issues. .load FILE ?ENTRY? Load an extension library .log FILE|off Turn logging on or off. FILE can be stderr/stdout .mode MODE ?TABLE? Set output mode .nullvalue STRING Use STRING in place of NULL values .once (-e|-x|FILE) Output for the next SQL command only to FILE .open ?OPTIONS? ?FILE? Close existing database and reopen FILE .output ?FILE? Send output to FILE or stdout if FILE is omitted .parameter CMD ... Manage SQL parameter bindings .print STRING... Print literal STRING .progress N Invoke progress handler after every N opcodes .prompt MAIN CONTINUE Replace the standard prompts .quit Exit this program .read FILE Read input from FILE .recover Recover as much data as possible from corrupt db. .restore ?DB? FILE Restore content of DB (default "main") from FILE .save FILE Write in-memory database into FILE .scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off .schema ?PATTERN? Show the CREATE statements matching PATTERN .selftest ?OPTIONS? Run tests defined in the SELFTEST table .separator COL ?ROW? Change the column and row separators .sha3sum ... Compute a SHA3 hash of database content .shell CMD ARGS... Run CMD ARGS... in a system shell .show Show the current values for various settings .stats ?on|off? Show stats or turn stats on or off .system CMD ARGS... Run CMD ARGS... in a system shell .tables ?TABLE? List names of tables matching LIKE pattern TABLE .testcase NAME Begin redirecting output to 'testcase-out.txt' .testctrl CMD ... Run various sqlite3_test_control() operations .timeout MS Try opening locked tables for MS milliseconds .timer on|off Turn SQL timer on or off .trace ?OPTIONS? Output each SQL statement as it is run .vfsinfo ?AUX? Information about the top-level VFS .vfslist List all available VFSes .vfsname ?AUX? Print the name of the VFS stack .width NUM1 NUM2 ... Set column widths for "column" mode sqlite> |
一言
MySQLの操作に慣れてからだと違和感凄い。
database一覧を表示しようと「show databases」叩いて表示されず、「そうだSQLiteだった」(.databasesか)となる。
SQLiteの操作は「.」始まりで、末尾には何も付けない(‘;’等不要)、一単語のみが多いと覚えれば直感的に操作できそう。
.exit 憶えとくと幸せになれると思う(sqliteなんもわからんときにexitとquitを試して駄目で諦めた黒歴史)。
構造を確認したいときは.schema
MySqlとかでテーブルの構造を確認したいときは「desc hogeTable」で指定していたが、SQLiteにはdescコマンドが無い。
SQLiteでテーブル構造を確認したい場合、「.schema hogeTable」で指定すると達成できる。因みに.schemaだけでも叩ける(全テーブルについての構造を表示させられる)。
1 2 3 4 5 6 7 8 |
sqlite> .schema users CREATE TABLE IF NOT EXISTS 'users'( 'id' INTEGER PRIMARY KEY AUTOINCREMENT, 'password' TEXT NOT NULL, 'name' TEXT NOT NULL, 'administrator' BOOLEAN ); sqlite> |
1 2 3 4 5 6 7 8 9 10 |
sqlite> .schema CREATE TABLE IF NOT EXISTS 'people'( 'id' INTEGER PRIMARY KEY AUTOINCREMENT, 'name' TEXT NOT NULL, 'mail' TEXT, 'age' INTEGER ); CREATE TABLE sqlite_sequence(name,seq); CREATE TABLE IF NOT EXISTS 'users'( 'id' INTEGER PRIMARY KEY AUTOINCREMENT, 'password' TEXT NOT NULL, 'name' TEXT NOT NULL, 'administrator' BOOLEAN ); sqlite> |
ご参考になれば幸いです。