SQLite three common commands for getting Started

Source: Internet
Author: User
Tags sqlite


3. Data display related commands



3.1 Set separator:. Separator separator



Help


Separator STRING Change separator used by output mode and. Import



Example


Default separator is |


sqlite> SELECT * FROM Cars;
1|Audi|52642
2|Mercedes|57127
3|Skoda|9000
4|Volvo|29000
5|Bentley|350000
6|Citroen|21000
7|Hummer|41400
8|Volkswagen|21600



Custom Separator


sqlite> .separator -
sqlite> SELECT * FROM Cars;
1-Audi-52642
2-Mercedes-57127
3-Skoda-9000
4-Volvo-29000
5-Bentley-350000
6-Citroen-21000
7-Hummer-41400
8-Volkswagen-21600
sqlite> .separator ;
sqlite> SELECT * FROM Cars;
1;Audi;52642
2;Mercedes;57127
3;Skoda;9000
4;Volvo;29000
5;Bentley;350000
6;Citroen;21000
7;Hummer;41400
8;Volkswagen;21600



3.2 Setting display mode:. Mode mode


?
.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


Default is List display mode


sqlite> SELECT * FROM Cars;
1|Audi|52642
2|Mercedes|57127
3|Skoda|9000
4|Volvo|29000
5|Bentley|350000
6|Citroen|21000
7|Hummer|41400
8|Volkswagen|21600


More Forth display mode


sqlite> .mode csv
sqlite> SELECT * FROM Cars;
1,Audi,52642
2,Mercedes,57127
3,Skoda,9000
4,Volvo,29000
5,Bentley,350000
6,Citroen,21000
7,Hummer,41400
8,Volkswagen,21600
sqlite> .mode tabs
sqlite> SELECT * FROM Cars;
1   Audi    52642
2   Mercedes    57127
3   Skoda   9000
4   Volvo   29000
5   Bentley 350000
6   Citroen 21000
7   Hummer  41400
8   Volkswagen  21600


3.3 Display title bar:. Headers on


 Echo on| Off Turn command echo on or off



Show title bar



sqlite> .headers on
sqlite> SELECT * FROM Cars;
Id  Name    Cost
1   Audi    52642
2   Mercedes    57127
3   Skoda   9000
4   Volvo   29000
5   Bentley 350000
6   Citroen 21000
7   Hummer  41400
8   Volkswagen  21600




Do not display the title bar


sqlite> .headers off
sqlite> SELECT * FROM Cars;
1   Audi    52642
2   Mercedes    57127
3   Skoda   9000
4   Volvo   29000
5   Bentley 350000
6   Citroen 21000
7   Hummer  41400
8   Volkswagen  21600



3.4 Set the display width of each column:. width NUM1 NUM2 ...


 width NUM1 NUM2 ... Set column widths for "column" mode



The default width does not appear to require this command



3.5 Set the null value to show what it looks like:. Nullvalue you want the null value format



By default, null values do not show anything, you can set it to the way you want it


sqlite> SELECT NULL,NULL,NULL;

sqlite> . nullvalue null
sqlite> SELECT NULL,NULL,NULL;
null    null    null



3.6 Lists the current display formatting settings:. Show


.show                  Show the current values for various settings



Example


bixiaopeng@bixiaopeng db$ sqlite3 wirelessqa.db
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .show
     echo: off
  explain: off
  headers: off
     mode: list
nullvalue: ""
   output: stdout
separator: "|"
    stats: off
    width:


If we want to reset the display format every time we go to the command line, it's a hassle, actually. All settings listed in the show command can be saved to a. sqliterc file so that it is automatically set each time you enter the command line.



The. Sqlterc file is saved under Linux in the user's home directory and can be saved to any directory under Windows, but you need to set the environment variable so that the database engine can find it, this is not an example, interested can see help.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.