---SQLite statement for the database

Source: Internet
Author: User
Tags sqlite

I. Basic creation Operation:

    • 1. Create a table

CREATE TABLE IF not EXISTS t_dog (name text, age Bolb, weight real);

    • 2. Inserting records

INSERT into T_shop (name, Left_count) VALUES (' fan ', 100);

    • 3. Modify the Record

UPDATE t_shop SET Price = 6288, Left_count = 0;

    • 4. Delete data from a table

DELETE from T_shop;

    • 5. Delete a table

DROP TABLE T_dog;

Two. Conditional statements

    • Change record

UPDATE t_shop SET left_count = 0 WHERE price < 1000;

    • Deleting records

DELETE from T_shop WHERE Left_count <, and price < 500;

DELETE from T_shop WHERE Left_count <, OR Price < 500;

    • Querying data

SELECT name, Price, left_count from T_shop;

SELECT * from T_shop WHERE left_count > 80;

  1. aliases : SELECT name Shop_name, price as Shop_price, Left_count inventory from T_shop s;
  2. count: SELECT Count (*) remaining quantity from T_shop WHERE left_count > 50;
  3. Descending query : SELECT *from t_shop ORDER by Left_count DESC;
  4. default ASC: SELECT *from t_shop ORDER by Left_count DESC, price ASC;
  5. limit: SELECT *from t_shop limit 2, 4;
    SELECT *from t_shop ORDER by Price DESC LIMIT 1, 10; ----Fetch the 2nd page with the highest price, 10 records;
  6. constraint : CREATE TABLE IF not EXISTS t_student (name text notnull, age integer);
  7. CREATE TABLE IF not EXISTS t_student (name text is not null - UNIQUE, age integer is not null);
  8. CREATE TABLE IF not EXISTS t_student (name text is not null - UNIQUE, age integer DEFAULT 1 NOT NULL );
  9. PRIMARY KEY constraint: primary key

CREATE TABLE IF not EXISTS t_class (ID integer PRIMARY KEY autoincrement, Name text not NULL UNIQUE);
INSERT into T_class (name) VALUES (' iOS ');
INSERT into T_class (name) VALUES (' andriod ');

---SQLite statement for the database

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.