创建表名 t_student 主键为 id
CREATE TABLE t_student (id integer PRIMARY KEY, name text,age integer,score real);
如果不存在就创建
CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY, name text,age integer,score real);
主键自动长
CREATE TABLE IF NOT EXISTS t_student (id integer PRIMARY KEY AUTOINCREMENT, name text,age integer,score real);
增加数据
INSERT INTO t_student (name,age,score) VALUES ('jams',10,10);
更新 全部设了99
UPDATE t_student SET score = 99;
删除内容 某
DELETE FROM t_student WHERE id = 2;
删除内容表内全部
DELETE FROM t_student;
删除整表
DROP TABLE t_student;
查找
SELECT * FROM t_student WHERE age > 50;
查找 总数
SELECT count(name) FROM t_student WHERE age > 50;
模糊查询 %5%
SELECT name , phone FROM t_student WHERE phone LIKE '%%%@%%'
/别名/
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;
/排序/
SELECT FROM t_student WHERE score > 50 ORDER BY age DESC;
SELECT FROM t_student WHERE score < 50 ORDER BY age ASC , score DESC;
/分页/ 从第几个后 开始 取多少个 0 5 5 5 10 5
SELECT * FROM t_student ORDER BY id ASC LIMIT 30, 10;
/简单约束/ 主键PRIMARY KEY 自动增长AUTOINCREMENT
不会空 NOT NULL 默认DEFAULT 1
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);
原文链接:http://www.jianshu.com/p/a397e239f354
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。