Author: alien

  • Khóa học miễn phí SQLite – Overview nhận dự án làm có lương

    SQLite – Overview



    This chapter helps you understand what is SQLite, how it differs from SQL, why it is needed and the way in which it handles the applications Database.

    SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is one of the fastest-growing database engines around, but that”s growth in terms of popularity, not anything to do with its size. The source code for SQLite is in the public domain.

    What is SQLite?

    SQLite is an in-process library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. It is a database, which is zero-configured, which means like other databases you do not need to configure it in your system.

    SQLite engine is not a standalone process like other databases, you can link it statically or dynamically as per your requirement with your application. SQLite accesses its storage files directly.

    Why SQLite?

    • SQLite does not require a separate server process or system to operate (serverless).

    • SQLite comes with zero-configuration, which means no setup or administration needed.

    • A complete SQLite database is stored in a single cross-platform disk file.

    • SQLite is very small and light weight, less than 400KiB fully configured or less than 250KiB with optional features omitted.

    • SQLite is self-contained, which means no external dependencies.

    • SQLite transactions are fully ACID-compliant, allowing safe access from multiple processes or threads.

    • SQLite supports most of the query language features found in SQL92 (SQL2) standard.

    • SQLite is written in ANSI-C and provides simple and easy-to-use API.

    • SQLite is available on UNIX (Linux, Mac OS-X, Android, iOS) and Windows (Win32, WinCE, WinRT).

    SQLite A Brief History

    • 2000 – D. Richard Hipp designed SQLite for the purpose of no administration required for operating a program.

    • 2000 – In August, SQLite 1.0 released with GNU Database Manager.

    • 2011 – Hipp announced to add UNQl interface to SQLite DB and to develop UNQLite (Document oriented database).

    SQLite Limitations

    There are few unsupported features of SQL92 in SQLite which are listed in the following table.

    Sr.No. Feature & Description
    1

    RIGHT OUTER JOIN

    Only LEFT OUTER JOIN is implemented.

    2

    FULL OUTER JOIN

    Only LEFT OUTER JOIN is implemented.

    3

    ALTER TABLE

    The RENAME TABLE and ADD COLUMN variants of the ALTER TABLE command are supported. The DROP COLUMN, ALTER COLUMN, ADD CONSTRAINT are not supported.

    4

    Trigger support

    FOR EACH ROW triggers are supported but not FOR EACH STATEMENT triggers.

    5

    VIEWs

    VIEWs in SQLite are read-only. You may not execute a DELETE, INSERT, or UPDATE statement on a view.

    6

    GRANT and REVOKE

    The only access permissions that can be applied are the normal file access permissions of the underlying operating system.

    SQLite Commands

    The standard SQLite commands to interact with relational databases are similar to SQL. They are CREATE, SELECT, INSERT, UPDATE, DELETE and DROP. These commands can be classified into groups based on their operational nature −

    DDL – Data Definition Language

    Sr.No. Command & Description
    1

    CREATE

    Creates a new table, a view of a table, or other object in database.

    2

    ALTER

    Modifies an existing database object, such as a table.

    3

    DROP

    Deletes an entire table, a view of a table or other object in the database.

    DML – Data Manipulation Language

    Sr.No. Command & Description
    1

    INSERT

    Creates a record

    2

    UPDATE

    Modifies records

    3

    DELETE

    Deletes records

    DQL – Data Query Language

    Sr.No. Command & Description
    1

    SELECT

    Retrieves certain records from one or more tables


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – Home nhận dự án làm có lương

    SQLite tutorial

    SQLite Tutorial







    SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain. This tutorial will give you a quick start with SQLite and make you comfortable with SQLite programming.

    Audience

    This tutorial has been prepared for beginners to help them understand the basic-to-advanced concepts related to SQLite Database Engine.

    Prerequisites

    Before you start practicing various types of examples given in this reference, we assume that you are already aware about what is a database, especially RDBMS and what is a computer programming language.

    Frequently Asked Questions about SQLite

    There are some very Frequently Asked Questions(FAQ) about SQLite, this section tries to answer them briefly.

    SQLite is a database management system used to store and manage data in a structured format. It is often used in applications that need to save data locally on a device or computer, such as mobile apps, desktop software, and embedded systems. SQLite allows developers to create databases, organize data into tables, and perform operations like inserting, updating, and querying data.

    You should use SQLite because it is easy to use and does not require a separate server to run. It is perfect for applications that need to store data locally on a device, like mobile apps or desktop software. SQLite is also fast and reliable, making it a good choice for projects where simplicity and efficiency are important. Plus, since it is self-contained, you can easily distribute SQLite databases with your application without worrying about additional setup for users.

    SQLite requires minimal maintenance compared to other database management systems. Since it is self-contained and doesn”t require a separate server, you don”t need to worry about installing updates or managing server configurations. However, regular backups of your SQLite databases are recommended to prevent data loss in case of accidents or errors. Additionally, you may need to periodically optimize your databases to improve performance, especially if they become large or complex.

    SQLite databases can become locked to prevent multiple processes from simultaneously making changes that could conflict with each other. When a process accesses an SQLite database, it acquires a lock to ensure exclusive access to the database while performing operations like writing data or executing transactions. This locking mechanism helps maintain data integrity and prevents data corruption by ensuring that only one process can modify the database at a time. Once the process completes its operations, it releases the lock, allowing other processes to access the database.

    SQLite is a type of relational database management system (RDBMS). It allows users to store, manage, and retrieve data in a structured format organized into tables with rows and columns. Users can define relationships between different tables, perform queries to retrieve specific data, and execute transactions to ensure data integrity.

    SQLite is written in the C programming language. This means that the core functionality of SQLite, including its engine for managing databases, is implemented using C code. However, SQLite provides interfaces for many programming languages, allowing developers to interact with SQLite databases using languages like Python, Java, C++, and more.

    Yes, SQLite is open source, which means its source code is freely available for anyone to view, modify, and distribute. This openness allows developers to inspect SQLite”s code, contribute improvements, and use it in their projects without restrictions.

    SQLite is known for its speed and efficiency in handling database operations. It is designed to be lightweight and optimized for quick access to data, making it fast for reading and writing data. Because SQLite is self-contained and doesn”t require a separate server, there is minimal overhead in communication, resulting in faster response times for database queries and transactions.

    SQLite was invented by D. Richard Hipp. He created SQLite to provide a simple, lightweight, and efficient database solution that could be embedded into software applications without requiring a separate server. Hipp designed SQLite to be fast, reliable, and easy to use, making it suitable for a wide range of projects and environments.

    The time it takes to learn SQLite can vary depending on your familiarity with databases and SQL (Structured Query Language). If you are completely new to databases, it might take a few days to understand the basics of SQLite and how to perform common operations like creating tables, inserting data, and querying information. With consistent practice and experimentation, you can become proficient in SQLite within a few weeks or months. However, mastering more advanced features and optimizing database performance could take longer and might require additional learning and experience.

    The latest version of SQLite is 3.36.0. However, it is important to note that new versions may have been released. SQLite developers regularly release updates to improve performance, fix bugs, and add new features. To find the most current version of SQLite, you can visit the official SQLite website or check the release notes on their GitHub repository.

    Yes, you can use SQLite in a browser environment. There are various ways to do this, but one common method is to use JavaScript libraries or frameworks that provide SQLite functionality directly within a web browser. These libraries include a JavaScript implementation of SQLite or provide wrappers around SQLite that allow you to execute SQL queries and interact with SQLite databases directly from your web browser.

    This enables you to create web applications that use SQLite databases without needing a server-side database management system. However, it is important to note that browser-based SQLite implementations may have limitations compared to using SQLite in a traditional server environment.

    SQLite is popular for several reasons. They are as follows −

    • Simplicity − It is easy to set up and use, making it accessible to developers of all skill levels.

    • Portability − SQLite databases are self-contained files that can be easily shared and transferred between different systems, making it convenient for use in various environments.

    • No Server Required − Unlike traditional database management systems, SQLite does not require a separate server to run, reducing setup complexity and resource requirements.

    • Efficiency − SQLite is lightweight and optimized for performance, allowing for fast data access and manipulation, even in resource-constrained environments.

    • Flexibility − It supports a wide range of SQL features and data types, making it suitable for a variety of applications, from mobile apps to desktop software to embedded systems.

    SQLite databases are stored as single files on your computer or device. When you create a SQLite database, it is saved as a single file with a .sqlite or .db extension. This file contains all the tables, rows, and other database objects you”ve defined, as well as the data you have inserted into the database. You can move, copy, or share SQLite database files just like any other file on your computer.

    To connect to SQLite, you need to use a programming language that supports SQLite and provides libraries or modules for interacting with SQLite databases −

    • Install SQLite − First, you need to ensure SQLite is installed on your system. Most systems come with SQLite pre-installed, but if not, you can download and install it from the official SQLite website.

    • Choose a Programming Language − Decide which programming language you want to use to interact with SQLite. Popular choices include Python, Java, C/C++, and many others.

    • Install SQLite Library or Module − Install the SQLite library or module for your chosen programming language. These libraries/modules provide functions or classes to interact with SQLite databases.

    • Connect to the Database − Use the functions or methods provided by the SQLite library/module to connect to your SQLite database. Generally, you will need to specify the path to your SQLite database file when establishing the connection.

    • Perform Operations − Once connected, you can execute SQL queries, insert, update, delete data, and perform other database operations using the functions or methods provided by the SQLite library/module.

    SQLite is like a small, lightweight tool for managing data in simple applications. It struggles with lots of users accessing data at once and isn”t great for huge amounts of information. It is best for small projects where simplicity is more important than handling lots of data or users.

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – Data Type nhận dự án làm có lương

    SQLite – Data Type



    SQLite data type is an attribute that specifies the type of data of any object. Each column, variable and expression has related data type in SQLite.

    You would use these data types while creating your tables. SQLite uses a more general dynamic type system. In SQLite, the datatype of a value is associated with the value itself, not with its container.

    SQLite Storage Classes

    Each value stored in an SQLite database has one of the following storage classes −

    Sr.No. Storage Class & Description
    1

    NULL

    The value is a NULL value.

    2

    INTEGER

    The value is a signed integer, stored in 1, 2, 3, 4, 6, or 8 bytes depending on the magnitude of the value.

    3

    REAL

    The value is a floating point value, stored as an 8-byte IEEE floating point number.

    4

    TEXT

    The value is a text string, stored using the database encoding (UTF-8, UTF-16BE or UTF-16LE)

    5

    BLOB

    The value is a blob of data, stored exactly as it was input.

    SQLite storage class is slightly more general than a datatype. The INTEGER storage class, for example, includes 6 different integer datatypes of different lengths.

    SQLite Affinity Type

    SQLite supports the concept of type affinity on columns. Any column can still store any type of data but the preferred storage class for a column is called its affinity. Each table column in an SQLite3 database is assigned one of the following type affinities −

    Sr.No. Affinity & Description
    1

    TEXT

    This column stores all data using storage classes NULL, TEXT or BLOB.

    2

    NUMERIC

    This column may contain values using all five storage classes.

    3

    INTEGER

    Behaves the same as a column with NUMERIC affinity, with an exception in a CAST expression.

    4

    REAL

    Behaves like a column with NUMERIC affinity except that it forces integer values into floating point representation.

    5

    NONE

    A column with affinity NONE does not prefer one storage class over another and no attempt is made to coerce data from one storage class into another.

    SQLite Affinity and Type Names

    Following table lists down various data type names which can be used while creating SQLite3 tables with the corresponding applied affinity.

    Data Type Affinity
    • INT
    • INTEGER
    • TINYINT
    • SMALLINT
    • MEDIUMINT
    • BIGINT
    • UNSIGNED BIG INT
    • INT2
    • INT8
    INTEGER
    • CHARACTER(20)
    • VARCHAR(255)
    • VARYING CHARACTER(255)
    • NCHAR(55)
    • NATIVE CHARACTER(70)
    • NVARCHAR(100)
    • TEXT
    • CLOB
    TEXT
    • BLOB
    • no datatype specified
    NONE
    • REAL
    • DOUBLE
    • DOUBLE PRECISION
    • FLOAT
    REAL
    • NUMERIC
    • DECIMAL(10,5)
    • BOOLEAN
    • DATE
    • DATETIME
    NUMERIC

    Boolean Datatype

    SQLite does not have a separate Boolean storage class. Instead, Boolean values are stored as integers 0 (false) and 1 (true).

    Date and Time Datatype

    SQLite does not have a separate storage class for storing dates and/or times, but SQLite is capable of storing dates and times as TEXT, REAL or INTEGER values.

    Sr.No. Storage Class & Date Formate
    1

    TEXT

    A date in a format like “YYYY-MM-DD HH:MM:SS.SSS”

    2

    REAL

    The number of days since noon in Greenwich on November 24, 4714 B.C.

    3

    INTEGER

    The number of seconds since 1970-01-01 00:00:00 UTC

    You can choose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – ATTACH Database nhận dự án làm có lương

    SQLite – ATTACH Database



    Consider a case when you have multiple databases available and you want to use any one of them at a time. SQLite ATTACH DATABASE statement is used to select a particular database, and after this command, all SQLite statements will be executed under the attached database.

    Syntax

    Following is the basic syntax of SQLite ATTACH DATABASE statement.

    ATTACH DATABASE ''DatabaseName'' As ''Alias-Name
    

    The above command will also create a database in case the database is already not created, otherwise it will just attach database file name with logical database ”Alias-Name”.

    Example

    If you want to attach an existing database testDB.db, then ATTACH DATABASE statement would be as follows −

    sqlite> ATTACH DATABASE ''testDB.db'' as ''TEST
    

    Use SQLite .database command to display attached database.

    sqlite> .database
    seq  name             file
    ---  ---------------  ----------------------
    0    main             /home/sqlite/testDB.db
    2    test             /home/sqlite/testDB.db
    

    The database names main and temp are reserved for the primary database and database to hold temporary tables and other temporary data objects. Both of these database names exist for every database connection and should not be used for attachment, otherwise you will get the following warning message.

    sqlite> ATTACH DATABASE ''testDB.db'' as ''TEMP
    Error: database TEMP is already in use
    sqlite> ATTACH DATABASE ''testDB.db'' as ''main
    Error: database TEMP is already in use
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – CREATE Database nhận dự án làm có lương

    SQLite – CREATE Database



    In SQLite, sqlite3 command is used to create a new SQLite database. You do not need to have any special privilege to create a database.

    Syntax

    Following is the basic syntax of sqlite3 command to create a database: −

    $sqlite3 DatabaseName.db
    

    Always, database name should be unique within the RDBMS.

    Example

    If you want to create a new database <testDB.db>, then SQLITE3 statement would be as follows −

    $sqlite3 testDB.db
    SQLite version 3.7.15.2 2013-01-09 11:53:05
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>
    

    The above command will create a file testDB.db in the current directory. This file will be used as database by SQLite engine. If you have noticed while creating database, sqlite3 command will provide a sqlite> prompt after creating a database file successfully.

    Once a database is created, you can verify it in the list of databases using the following SQLite .databases command.

    sqlite>.databases
    seq  name             file
    ---  ---------------  ----------------------
    0    main             /home/sqlite/testDB.db
    

    You will use SQLite .quit command to come out of the sqlite prompt as follows −

    sqlite>.quit
    $
    

    The .dump Command

    You can use .dump dot command to export complete database in a text file using the following SQLite command at the command prompt.

    $sqlite3 testDB.db .dump > testDB.sql
    

    The above command will convert the entire contents of testDB.db database into SQLite statements and dump it into ASCII text file testDB.sql. You can perform restoration from the generated testDB.sql in a simple way as follows −

    $sqlite3 testDB.db < testDB.sql
    

    At this moment your database is empty, so you can try above two procedures once you have few tables and data in your database. For now, let”s proceed to the next chapter.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – Syntax nhận dự án làm có lương

    SQLite – Syntax



    SQLite is followed by unique set of rules and guidelines called Syntax. This chapter lists all the basic SQLite Syntax.

    Case Sensitivity

    The important point to be noted is that SQLite is case insensitive, i.e. the clauses GLOB and glob have the same meaning in SQLite statements.

    Comments

    SQLite comments are extra notes, which you can add in your SQLite code to increase its readability and they can appear anywhere; whitespace can occur, including inside expressions and in the middle of other SQL statements but they cannot be nested.

    SQL comments begin with two consecutive “-” characters (ASCII 0x2d) and extend up to and including the next newline character (ASCII 0x0a) or until the end of input, whichever comes first.

    You can also use C-style comments, which begin with “/*” and extend up to and including the next “*/” character pair or until the end of input, whichever comes first. C-style comments can span multiple lines.

    sqlite> .help -- This is a single line comment
    

    SQLite Statements

    All the SQLite statements start with any of the keywords like SELECT, INSERT, UPDATE, DELETE, ALTER, DROP, etc., and all the statements end with a semicolon (;).

    SQLite ANALYZE Statement

    ANALYZE;
    or
    ANALYZE database_name;
    or
    ANALYZE database_name.table_name;
    

    SQLite AND/OR Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE CONDITION-1 {AND|OR} CONDITION-2;
    

    SQLite ALTER TABLE Statement

    ALTER TABLE table_name ADD COLUMN column_def...;
    

    SQLite ALTER TABLE Statement (Rename)

    ALTER TABLE table_name RENAME TO new_table_name;
    

    SQLite ATTACH DATABASE Statement

    ATTACH DATABASE ''DatabaseName'' As ''Alias-Name
    

    SQLite BEGIN TRANSACTION Statement

    BEGIN;
    or
    BEGIN EXCLUSIVE TRANSACTION;
    

    SQLite BETWEEN Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE column_name BETWEEN val-1 AND val-2;
    

    SQLite COMMIT Statement

    COMMIT;
    

    SQLite CREATE INDEX Statement

    CREATE INDEX index_name
    ON table_name ( column_name COLLATE NOCASE );
    

    SQLite CREATE UNIQUE INDEX Statement

    CREATE UNIQUE INDEX index_name
    ON table_name ( column1, column2,...columnN);
    

    SQLite CREATE TABLE Statement

    CREATE TABLE table_name(
       column1 datatype,
       column2 datatype,
       column3 datatype,
       .....
       columnN datatype,
       PRIMARY KEY( one or more columns )
    );
    

    SQLite CREATE TRIGGER Statement

    CREATE TRIGGER database_name.trigger_name
    BEFORE INSERT ON table_name FOR EACH ROW
    BEGIN
       stmt1;
       stmt2;
       ....
    END;
    

    SQLite CREATE VIEW Statement

    CREATE VIEW database_name.view_name AS
    SELECT statement....;
    

    SQLite CREATE VIRTUAL TABLE Statement

    CREATE VIRTUAL TABLE database_name.table_name USING weblog( access.log );
    or
    CREATE VIRTUAL TABLE database_name.table_name USING fts3( );
    

    SQLite COMMIT TRANSACTION Statement

    COMMIT;
    

    SQLite COUNT Clause

    SELECT COUNT(column_name)
    FROM table_name
    WHERE CONDITION;
    

    SQLite DELETE Statement

    DELETE FROM table_name
    WHERE {CONDITION};
    

    SQLite DETACH DATABASE Statement

    DETACH DATABASE ''Alias-Name
    

    SQLite DISTINCT Clause

    SELECT DISTINCT column1, column2....columnN
    FROM table_name;
    

    SQLite DROP INDEX Statement

    DROP INDEX database_name.index_name;
    

    SQLite DROP TABLE Statement

    DROP TABLE database_name.table_name;
    

    SQLite DROP VIEW Statement

    DROP INDEX database_name.view_name;
    

    SQLite DROP TRIGGER Statement

    DROP INDEX database_name.trigger_name;
    

    SQLite EXISTS Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE column_name EXISTS (SELECT * FROM   table_name );
    

    SQLite EXPLAIN Statement

    EXPLAIN INSERT statement...;
    or
    EXPLAIN QUERY PLAN SELECT statement...;
    

    SQLite GLOB Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE column_name GLOB { PATTERN };
    

    SQLite GROUP BY Clause

    SELECT SUM(column_name)
    FROM table_name
    WHERE CONDITION
    GROUP BY column_name;
    

    SQLite HAVING Clause

    SELECT SUM(column_name)
    FROM table_name
    WHERE CONDITION
    GROUP BY column_name
    HAVING (arithematic function condition);
    

    SQLite INSERT INTO Statement

    INSERT INTO table_name( column1, column2....columnN)
    VALUES ( value1, value2....valueN);
    

    SQLite IN Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE column_name IN (val-1, val-2,...val-N);
    

    SQLite Like Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE column_name LIKE { PATTERN };
    

    SQLite NOT IN Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE column_name NOT IN (val-1, val-2,...val-N);
    

    SQLite ORDER BY Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE CONDITION
    ORDER BY column_name {ASC|DESC};
    

    SQLite PRAGMA Statement

    PRAGMA pragma_name;
    
    For example:
    
    PRAGMA page_size;
    PRAGMA cache_size = 1024;
    PRAGMA table_info(table_name);
    

    SQLite RELEASE SAVEPOINT Statement

    RELEASE savepoint_name;
    

    SQLite REINDEX Statement

    REINDEX collation_name;
    REINDEX database_name.index_name;
    REINDEX database_name.table_name;
    

    SQLite ROLLBACK Statement

    ROLLBACK;
    or
    ROLLBACK TO SAVEPOINT savepoint_name;
    

    SQLite SAVEPOINT Statement

    SAVEPOINT savepoint_name;
    

    SQLite SELECT Statement

    SELECT column1, column2....columnN
    FROM table_name;
    

    SQLite UPDATE Statement

    UPDATE table_name
    SET column1 = value1, column2 = value2....columnN=valueN
    [ WHERE  CONDITION ];
    

    SQLite VACUUM Statement

    VACUUM;
    

    SQLite WHERE Clause

    SELECT column1, column2....columnN
    FROM table_name
    WHERE CONDITION;
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – Commands nhận dự án làm có lương

    SQLite – Commands



    This chapter will take you through simple and useful commands used by SQLite programmers. These commands are called SQLite dot commands and exception with these commands is that they should not be terminated by a semi-colon (;).

    Let”s start with typing a simple sqlite3 command at command prompt which will provide you with SQLite command prompt where you will issue various SQLite commands.

    $sqlite3
    SQLite version 3.3.6
    Enter ".help" for instructions
    sqlite>
    

    For a listing of the available dot commands, you can enter “.help” any time. For example −

    sqlite>.help
    

    The above command will display a list of various important SQLite dot commands, which are listed in the following table.

    Sr.No. Command & Description
    1

    .backup ?DB? FILE

    Backup DB (default “main”) to FILE

    2

    .bail ON|OFF

    Stop after hitting an error. Default OFF

    3

    .databases

    List names and files of attached databases

    4

    .dump ?TABLE?

    Dump the database in an SQL text format. If TABLE specified, only dump tables matching LIKE pattern TABLE

    5

    .echo ON|OFF

    Turn command echo on or off

    6

    .exit

    Exit SQLite prompt

    7

    .explain ON|OFF

    Turn output mode suitable for EXPLAIN on or off. With no args, it turns EXPLAIN on

    8

    .header(s) ON|OFF

    Turn display of headers on or off

    9

    .help

    Show this message

    10

    .import FILE TABLE

    Import data from FILE into TABLE

    11

    .indices ?TABLE?

    Show names of all indices. If TABLE specified, only show indices for tables matching LIKE pattern TABLE

    12

    .load FILE ?ENTRY?

    Load an extension library

    13

    .log FILE|off

    Turn logging on or off. FILE can be stderr/stdout

    14

    .mode MODE

    Set output mode where MODE is one of −

    • csv − Comma-separated values

    • column − Left-aligned columns.

    • 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

    15

    .nullvalue STRING

    Print STRING in place of NULL values

    16

    .output FILENAME

    Send output to FILENAME

    17

    .output stdout

    Send output to the screen

    18

    .print STRING…

    Print literal STRING

    19

    .prompt MAIN CONTINUE

    Replace the standard prompts

    20

    .quit

    Exit SQLite prompt

    21

    .read FILENAME

    Execute SQL in FILENAME

    22

    .schema ?TABLE?

    Show the CREATE statements. If TABLE specified, only show tables matching LIKE pattern TABLE

    23

    .separator STRING

    Change separator used by output mode and .import

    24

    .show

    Show the current values for various settings

    25

    .stats ON|OFF

    Turn stats on or off

    26

    .tables ?PATTERN?

    List names of tables matching a LIKE pattern

    27

    .timeout MS

    Try opening locked tables for MS milliseconds

    28

    .width NUM NUM

    Set column widths for “column” mode

    29

    .timer ON|OFF

    Turn the CPU timer measurement on or off

    Let”s try .show command to see default setting for your SQLite command prompt.

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

    Make sure there is no space in between sqlite> prompt and dot command, otherwise it will not work.

    Formatting Output

    You can use the following sequence of dot commands to format your output.

    sqlite>.header on
    sqlite>.mode column
    sqlite>.timer on
    sqlite>
    

    The above setting will produce the output in the following format.

    ID          NAME        AGE         ADDRESS     SALARY
    ----------  ----------  ----------  ----------  ----------
    1           Paul        32          California  20000.0
    2           Allen       25          Texas       15000.0
    3           Teddy       23          Norway      20000.0
    4           Mark        25          Rich-Mond   65000.0
    5           David       27          Texas       85000.0
    6           Kim         22          South-Hall  45000.0
    7           James       24          Houston     10000.0
    CPU Time: user 0.000000 sys 0.000000
    

    The sqlite_master Table

    The master table holds the key information about your database tables and it is called sqlite_master. You can see its schema as follows −

    sqlite>.schema sqlite_master
    

    This will produce the following result.

    CREATE TABLE sqlite_master (
       type text,
       name text,
       tbl_name text,
       rootpage integer,
       sql text
    );
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQLite – Installation nhận dự án làm có lương

    SQLite – Installation



    SQLite is famous for its great feature zero-configuration, which means no complex setup or administration is needed. This chapter will take you through the process of setting up SQLite on Windows, Linux and Mac OS X.

    Install SQLite on Windows

    • Step 1 − Go to , and download precompiled binaries from Windows section.

    • Step 2 − Download sqlite-shell-win32-*.zip and sqlite-dll-win32-*.zip zipped files.

    • Step 3 − Create a folder C:>sqlite and unzip above two zipped files in this folder, which will give you sqlite3.def, sqlite3.dll and sqlite3.exe files.

    • Step 4 − Add C:>sqlite in your PATH environment variable and finally go to the command prompt and issue sqlite3 command, which should display the following result.

    C:>sqlite3
    SQLite version 3.7.15.2 2013-01-09 11:53:05
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>
    

    Install SQLite on Linux

    Today, almost all the flavours of Linux OS are being shipped with SQLite. So you just issue the following command to check if you already have SQLite installed on your machine.

    $sqlite3
    SQLite version 3.7.15.2 2013-01-09 11:53:05
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>
    

    If you do not see the above result, then it means you do not have SQLite installed on your Linux machine. Following are the following steps to install SQLite −

    • Step 1 − Go to and download sqlite-autoconf-*.tar.gz from source code section.

    • Step 2 − Run the following command −

    $tar xvfz sqlite-autoconf-3071502.tar.gz
    $cd sqlite-autoconf-3071502
    $./configure --prefix=/usr/local
    $make
    $make install
    

    The above command will end with SQLite installation on your Linux machine. Which you can verify as explained above.

    Install SQLite on Mac OS X

    Though the latest version of Mac OS X comes pre-installed with SQLite but if you do not have installation available then just follow these following steps −

    • Step 1 − Go to , and download sqlite-autoconf-*.tar.gz from source code section.

    • Step 2 − Run the following command −

    $tar xvfz sqlite-autoconf-3071502.tar.gz
    $cd sqlite-autoconf-3071502
    $./configure --prefix=/usr/local
    $make
    $make install
    

    The above procedure will end with SQLite installation on your Mac OS X machine. Which you can verify by issuing the following command −

    $sqlite3
    SQLite version 3.7.15.2 2013-01-09 11:53:05
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite>
    

    Finally, you have SQLite command prompt where you can issue SQLite commands for your exercises.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Drop Database nhận dự án làm có lương

    SQL – DROP Database

    Table of content


    The SQL DROP DATABASE statement is used to delete an existing database along with all the data such as tables, views, indexes, stored procedures, and constraints.

    SQL DROP Database Statement

    Following are the important points to remember before you delete an existing database −

    • Make sure you have taken proper before you delete it.
    • Make sure no other application is connected and using this database.
    • Make sure you have the necessary privilege to delete the database. Usually an admin can delete the databaase.

    Syntax

    Following is the syntax to delete a database in SQL

    DROP DATABASE DatabaseName;
    

    Here, the DatabaseName is the name of the database that you want to delete. A database name is always unique within the RDBMS.

    Example

    First of all, let us create multiple databases into database system using the following SQL queries −

    CREATE DATABASE testDB1;
    CREATE DATABASE testDB2;
    CREATE DATABASE testDB3;
    CREATE DATABASE testDB4;
    

    Let us verify whether the databases are created or not using the following query −

    SHOW DATABASES;
    

    This will list down all the available databases:

    Database
    information_schema
    mysql
    performance_schema
    testDB1
    testDB2
    testDB3
    testDB4

    Now, let us try to delete the testDB1 database using the SQL DROP DATABASE statement −

    DROP DATABASE testDB1;
    

    Once we have deleted the testDB1 database, we can verify whether it is deleted or not using the SQL SHOW DATABASES statement −

    SHOW DATABASES;
    

    This will list down all the available databases:

    Database
    information_schema
    mysql
    performance_schema
    testDB2
    testDB3
    testDB4

    That”s it! we have successfully deleted a database in SQL.

    SQL DROP DATABASE IF EXISTS Statement

    The SQL DROP DATABASE IF EXISTS statement includes a condition to check whether the database exists before trying to delete it. If the database does not exist in the database system, the “DROP DATABASE IF EXISTS” statement does not raise an error, but it simply terminates without taking any action.

    Syntax

    Following is the syntax of the DROP DATABASE IF EXISTS statement in SQL −

    DROP DATABASE IF EXISTS DatabaseName;
    

    Here, the DatabaseName is the name of the database that you want to delete.

    Example

    Let us try to delete an existing database testDB2 in the database system using the following SQL statement −

    DROP DATABASE IF EXISTS testDB2;
    

    When we execute the above SQL statement, the output is obtained as follows −

    Query OK, 0 rows affected, 3 warnings (0.024 sec)
    

    Dropping the Database that doesn”t Exist

    Let us try to drop a database testDB2 that doesn”t exist in the database system using the following SQL statement −

    DROP DATABASE IF EXISTS testDB2;
    

    When we execute the above SQL statement, the output is obtained as follows −

    Query OK, 0 rows affected, 1 warning (0.000 sec)
    

    Deleting Multiple Databases

    You can drop multiple databases using the SQL DROP DATABASE statement as follows:

    DROP DATABASE testDB3, testDB4;
    

    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc

  • Khóa học miễn phí SQL – Discussion nhận dự án làm có lương

    Discuss SQL



    SQL is a database computer language designed for the retrieval and management of data in a relational database. SQL stands for Structured Query Language. This tutorial will give you a quick start to SQL. It covers most of the topics required for a basic understanding of SQL and to get a feel of how it works.


    Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc