sqlite數據庫

運行SQLite3 shell程序:

C:\>SQLite3_3_5.exe

SQLite version 3.3.5

Enter ".help" for instructions

創建表AuditData:

sqlite> create table AuditDate (Time text,      OperateType integer,    UserName text,EncrypteBox_SrcDisk text,EncrypteBox_SrcName text,EncrypteBox_SrcPath text,       EncrypteBox_SrcEx text,EncrypteBox_DesDisk text,EncrypteBox_DesName text,EncrypteBox_DesPath text,EncrypteBox_De*** text,FileName text,FileSrcPath text,FileDesPath text,FileExplain text);

查詢表AuditDate的內容:

sqlite> select * from AuditDate

   ...> ;

查詢當前數據庫下的所有表名稱:

sqlite> .table

AuditDate

使用SQL語句查詢表結構信息:

sqlite> select * from sqlite_master where type = "table";

table|AuditDate|AuditDate|2|CREATE TABLE AuditDate (Time text,  OperateType integer,    UserName text,EncrypteBox_SrcDisk text,EncrypteBox_SrcName text,EncrypteBox_SrcPath text,       EncrypteBox_SrcEx text,EncrypteBox_DesDisk text,EncrypteBox_DesName text,EncrypteBox_DesPath text,EncrypteBox_De*** text,FileName text,FileSrcPath text,FileDesPath text,FileExplain text)


查看SQLite3幫助命令:
sqlite> .help
.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
.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

.width NUM NUM ...     Set column widths for "column" mode

退出SQLite3:

sqlite> .quit

啓動SQLite3,創建1.db,並連接到該數據庫:

C:\>SQLite3_3_5.exe 1.db
SQLite version 3.3.5

Enter ".help" for instructions

將表結構輸出:

sqlite> .dump
BEGIN TRANSACTION;
CREATE TABLE AuditDate (Time text,      OperateType integer,    UserName text,EncrypteBox_SrcDisk text,EncrypteBox_SrcName text,EncrypteBox_SrcPath text,EncrypteBox_SrcEx text,EncrypteBox_DesDisk text,EncrypteBox_DesName text,EncrypteBox_DesPath text,EncrypteBox_De*** text,FileName text,FileSrcPath text,FileDesPath text,FileExplain text);
COMMIT;

將AuditDate表的表結構輸出:

sqlite> .dump AuditDate
BEGIN TRANSACTION;
CREATE TABLE AuditDate (Time text,      OperateType integer,    UserName text,En
crypteBox_SrcDisk text,EncrypteBox_SrcName text,EncrypteBox_SrcPath text,
EncrypteBox_SrcEx text,EncrypteBox_DesDisk text,EncrypteBox_DesName text,Encrypt
eBox_DesPath text,EncrypteBox_De*** text,FileName text,FileSrcPath text,FileDesP
ath text,FileExplain text);
COMMIT;

將查詢結果輸出到文件1.txt:

sqlite> .output 1.txt

將查詢結果輸出到屏幕:

sqlite> .output stdout
sqlite> select * from sqlite_master where type = "table";
table|AuditDate|AuditDate|2|CREATE TABLE AuditDate (Time text,  OperateType integer,    UserName text,EncrypteBox_SrcDisk text,EncrypteBox_SrcName text,Encrypte
Box_SrcPath text,       EncrypteBox_SrcEx text,EncrypteBox_DesDisk text,EncrypteBox_DesName text,EncrypteBox_DesPath text,EncrypteBox_De*** text,FileName text,F

ileSrcPath text,FileDesPath text,FileExplain text)

創建表adb,並且向其中插入數據,然後查詢該表中字段的數據類型:

sqlite>CREATE TABLE adb (name text)
sqlite> select typeof(name) from adb;
sqlite> insert into adb (name) values ('ddd');
sqlite> select typeof(name) from adb;
text
sqlite>



查看整個數據庫的表結構

sqlite> .schema
CREATE TABLE a (time integer not null default current_timestamp,name text);
CREATE TABLE ab (time integer,name text);
CREATE TABLE abc (name text,time integer not null default current_timestamp);
CREATE TABLE abcd (name text,time integer not null default current_timestamp);
CREATE TABLE abcde (name text,time integer );

顯示錶頭:

sqlite> .head on
sqlite> select * from abcde;
name|time
aaa|
sqlite>

查看當前SQlite3運行時的配置信息:

sqlite> .show
     echo: off
  explain: off
  headers: on
     mode: list
nullvalue: ""
   output: stdout
separator: "|"
    width:
sqlite>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章