iOS Development Database Chapter---"SQLite common statements"

Source: Internet
Author: User

/* Simple constraint */
CREATE TABLE IF not EXISTS t_student (ID integer PRIMARY KEY autoincrement, name TEXT, age INTEGER);
CREATE TABLE IF not EXISTS t_student (ID integer PRIMARY KEY autoincrement, name TEXT NOT NULL, age INTEGER not NULL);
CREATE TABLE IF not EXISTS t_student (ID integer PRIMARY KEY autoincrement, name TEXT UNIQUE, age INTEGER);
CREATE TABLE IF not EXISTS t_student (ID integer PRIMARY KEY autoincrement, name TEXT, age INTEGER DEFAULT 1);

/* Paging */
SELECT * from t_student ORDER by ID ASC LIMIT 30, 10;

/* Sort */
SELECT * from T_student WHERE score > ORDER by age DESC;
SELECT * from T_student WHERE score < The ORDER by age ASC, score DESC;

/* Metering */
SELECT COUNT (*) from t_student WHERE age > 50;

/* Alias */
SELECT name as MyName, age as MyAge, score as Myscore from T_student;
SELECT name MyName, age MyAge, score myscore from T_student;
SELECT s.name myName, S.age myAge, S.score myscore from t_student s WHERE s.age > 50;

/* Query */
SELECT name, age, score from t_student;
SELECT * from T_student;

/* Modify the specified data */
UPDATE t_student SET name = ' MM ' WHERE age = 10;
UPDATE t_student SET name = ' WW ' WHERE age is 7;
UPDATE t_student SET name = ' Xxoo ' WHERE age < 20;
UPDATE t_student SET name = ' nnmm ' WHERE age < score > 10;

/* Delete Data */
DELETE from T_student;

/* Update Data */
UPDATE t_student SET name = ' LNJ ';

/* Insert Data */

INSERT into T_student (age, score, name) VALUES (' + ', ' + ', ' Jonathan ');
INSERT into T_student (name, age) VALUES (' Lee ', ' 28 ');
INSERT into T_student (score) VALUES (100);

/* Insert Data */
INSERT into T_student (name, age, score) VALUES (' Lee ', ' 28 ', 100);



/* Delete Table */
DROP TABLE IF EXISTS t_student;
DROP TABLE t_student;

/* CREATE TABLE */
CREATE TABLE IF not EXISTS t_student (id INTEGER, name TEXT, age, score REAL);
/* CREATE table and add primary key Master setting primary key active growth */
CREATE TABLE IF not EXISTS t_student (ID integer PRIMARY KEY autoincrement, name TEXT, age INTEGER, score REAL);
/* CREATE table and add primary key */
CREATE TABLE IF not EXISTS t_student (ID integer, name TEXT, age INTEGER, score REAL, PRIMARY KEY (id));

iOS Development Database Chapter---"SQLite common statements"

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.