SQLite - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

SQLite Commands

SQLite Commands

shape Description

The SQLite Commands are extremely basic and effectively comprehends for all the SQLite programmers. SQLite Commands are also called as SQLite Dot Commands. The special case with these speck orders is that it does not end using semi colon ;. Each and every function in SQLite will be described in the operations given below, such as typing .help in SQLite Commands gives the entire details. [c]sqlite> .help .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 .changes on|off Show number of rows changed by SQL .clone NEWDB Clone data into NEWDB from the existing database .databases List names and files of attached databases .dbinfo ?DB? Show status information about the database .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 .eqp on|off|full Enable or disable automatic EXPLAIN QUERY PLAN .exit Exit this program .explain ?on|off|auto? Turn EXPLAIN output mode on or off or to automatic .fullschema ?--indent? Show schema and the content of sqlite_stat tables .headers on|off Turn display of headers on or off .help Show this message .import FILE TABLE Import data from FILE into TABLE .indexes ?TABLE? Show names of all indexes If TABLE specified, only show indexes for tables matching LIKE pattern TABLE. .limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT .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 where MODE is one of: ascii Columns/rows delimited by 0x1F and 0x1E 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 strings tabs Tab-separated values tcl TCL list elements .nullvalue STRING Use STRING in place of NULL values .once FILENAME Output for the next SQL command only to FILENAME .open ?FILENAME? Close existing database and reopen FILENAME .output ?FILENAME? Send output to FILENAME or stdout .print STRING... Print literal STRING .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 .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 Add --indent for pretty-printing .separator COL ?ROW? Change the column separator and optionally the row separator for both the output mode and .import .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 If TABLE specified, only list tables matching LIKE pattern TABLE. .timeout MS Try opening locked tables for MS milliseconds .timer on|off Turn SQL timer on or off .trace FILE|off 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 Negative values right-justify[/c]   SQLite has standard definition languages and can be classified into 3 types such as :

Data Defination Language

shape Description

Data Definition Language(DDL) is used to define data in Database Server. DDL statements explains, how the pattern of data should be there in the database schema table. DDL statements are classified into the following types:

Data manipulation Language

shape Description

Data manipulation language is utilized to manage data within the table. i.e. DML statements are used to manage data inside the schema objects, and includes most common standard query language statements such as select command and insert command. DML allows to add and modify the database table. Following are the DML statements

Data Query Language

shape Description

DQL empowers the user to retrieve the required data from the database. Following are the DQL statements :

Create

shape Description

By using Create command in SQLite Commands, new table can be defined in the Database Server and the table name can be any character followed by size. This command will access the create privilege for the database and the table name should be unique in the database.

shape Syntax

Create table <table_name>(Post_id INTEGER NOT NULL PRIMARY KEY AUTO INCREMENT,name TEXT NOT NULL,email TEXT NOT NULL);
table_name => Any accurate table. column_name => The operation that can be performed on a column in the table.

shape Examples

By using the below example, new table can be created by using create command. [c] sqlite> Create table comment(post_id INTEGER NOT NULL PRIMARY KEY AUTO INCREMENT, name TEXT NOT NULL,email TEXT NOT NULL); sqlite> .tables comment[/c] In the above example, a table comment is defined with column names post_id, name, and email.

Insert

shape Description

By using insert command new record can be inserted in the existing database table. i.e, inserting field value like name, email id and salary can be inserted.

shape Syntax

Insert into <table_name> values(<value1>,<value2>,<value3>.......);
table name => Accurate table. values => values are the column values.

shape Examples

By using the below example, the concept of insert command can be understood easily. [sql]sqlite> Create table comment(post_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL,email TEXT NOT NULL); sqlite> .tables comment sqlite> Insert into comment(name,email)values('John','shah@gmail.com'); sqlite> Insert into comment(name,email)values('Mike','chah@gmail.com'); sqlite> select * from comment; 1|John|shah@gmail.com 2|Mike|chah@gmail.com[/sql] The above example tells that, when insert command is performed on the table comment then the table will accept the values and stores in the table database.

select

shape Description

Select statement of SQLite Commands will display all the details in the entire table that the user has entered.Select post_id, name, email id from comment;

shape Syntax

Select <value1>,<value2>,<valuen>from <table_name>;
table name => The accurate table. values => values are the column values.

shape Examples

By viewing the below example, the concept of select command can be understood easily. [sql]Select * from comment;[/sql] The above example tells that, when select command is performed on the table comment then it will accept the values and stores in the table database.

Summary

shape Key Points

  • SQLite Commands - Basic and effectively comprehend for all the SQLite programmers.
  • Data Definition Language - Used to define data in database server.
  • Data Manipulation Language - Used to manage data in database server.
  • Data Query Language - Retrieves data from the database server.