SQLite database operation practices

Source: Internet
Author: User
Tags type null
SQLite database operation practices: SQLite storage type null

SQLite database operation practice SQLite storage type null-null integer-signed integer, auto-incrementing column definition id integer primary key autoincrement real-floating point number, stored as an 8-byte IEEE floating point text-text string using database encoding (UTF-8, UTF-16BE, or UTF-16LE) for storage blob-binary

SQLite database operation practices
SQLite storage type
Null-null
Integer-signed integer, id defined in the auto-increment column integer primary key autoincrement
Real-floating point number, which is stored as an 8-byte IEEE floating point number
Text-text strings are stored using database encoding (UTF-8, UTF-16BE, or UTF-16LE)
Blob-binary data, slices, sounds, and so on
Other data types such as datetime, varchar, nvarchar, decimal, float, double, and bigint can also be accepted.

Last login: Tue Jan 7 19:05:33 2014 from 192.168.10.1
[Myth @ host10 ~] $ Su
Password:
[Root @ host10 myth] # pwd // display the current working directory

/Home/myth

Go to the SQLite command line to create a database and open the database

[Root @ host10 myth] # sqlite3 bookstore. db
SQLite version 3.6.20
Enter ". help" for instructions
Enter SQL statements terminated with ";"
Sqlite>. databases
Seq name file
----------------------------------------------------------------------------
0 main/home/myth/bookstore. db
Sqlite>
Sqlite>. quit // exit the SQLite command line Environment

[Root @ host10 myth] #

Open Database

[Root @ host10 myth] # sqlite3 bookstore. db // if the database already exists, open the database
SQLite version 3.6.20
Enter ". help" for instructions
Enter SQL statements terminated with ";"
Sqlite>. help // view help information
. Backup? DB? FILE Backup DB (default "main") to FILE
. 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
If TABLE specified, only dump tables matching
LIKE pattern TABLE.
. 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.
. Genfkey? OPTIONS? Options are:
-- No-drop: Do not drop old fkey triggers.
-- Ignore-errors: Ignore tables with fkey errors
-- Exec: Execute generated SQL immediately
See file tool/genfkey. README in the source
Distribution for further information.
. 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
If TABLE specified, only show indices for tables
Matching LIKE pattern TABLE.
. Load FILE? ENTRY? Load an extension library
. Mode MODE? TABLE? Set output mode where MODE is one:
Csv Comma-separated values
Column Left-aligned columns. (See. width)
Html HTML
























Sqlite>

Create a table

Sqlite> create table books (id integer primary key, title nvarchar (50), pubdate datetime );
Sqlite> create table publishers (id integer primary key, name varchar (20 ));
Sqlite>. tables // View tables in the database
Books publishers
Sqlite>. schema books // displays the table structure
Create table books (id integer primary key, title nvarchar (50), pubdate datetime );
Sqlite>
Sqlite> alter table books add column publisher text not null default ''collate nocase; // add table Fields
Sqlite>. schema books // displays the table structure
Create table books (id integer primary key, title nvarchar (50), pubdate datetime, publisher text not null default ''collate nocase );
Sqlite>
Sqlite> alter table publishers rename to authors; // modify the table name
Sqlite>. tables // View tables in the database
Authors books

Sqlite>

Modify Field name

// Modify the field name and data type (similar to deleting a field). A simpler method is to delete the table and recreate it without any important data.

Sqlite> alter table authors rename to authorsOld;
Sqlite> create table authors (id integer primary key, author nvarchar (20 ));
Sqlite> insert into authors select id, name from authorsOld;
Sqlite> drop table authorsOld;
Sqlite>. schema authors
Create table authors (id integer primary key, author nvarchar (20 ));

// You can also export data into an insert statement, delete the table, recreate the table, and execute all insert statements to add data.

Show all database table names

CodeInsert SQL insert statements for TABLELine One value per lineList Values delimited by. separator stringTabs Tab-separated valuesTcl 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. Restore? DB? FILE Restore content of DB (default "main") from FILE. Schema? TABLE? Show the CREATE statementsIf TABLE specified, only show tables matchingLIKE pattern TABLE.. Separator STRING Change separator used by output mode and. import. Show Show show the current values for various settings. Tables? TABLE? List names of tablesIf TABLE specified, only list tables matchingLIKE pattern TABLE.. Timeout MS Try opening locked tables for MS milliseconds. Width NUM... Set column widths for "column" mode. Timer ON | OFF Turn the CPU timer measurement on or off

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.