码迷,mamicode.com
首页 > 数据库 > 详细

SQLite语句

时间:2015-01-27 00:23:19      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

sqlite3是一个可以放在工程中的本地数据库,其大小几百k,通过对c语言的封装,sqlite3有自己的语句对数据库中的数据进行处理,一般应用在对数据进行复杂处理的app中。

/*简单约束*/

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);

 

/*分页*/

SELECT * FROM t_student ORDER BY id ASC LIMIT 30, 10;

 

/*排序*/

SELECT * FROM t_student WHERE score > 50 ORDER BY age DESC;

SELECT * FROM t_student WHERE score < 50 ORDER BY age ASC , score DESC;

 

/*计量*/

SELECT COUNT(*) FROM t_student WHERE age > 50;

 

/*别名*/

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 name, age, score FROM t_student;

SELECT * FROM t_student;

 

/*修改指定数据*/

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 < 50 and score > 10;

 

/*删除数据*/

DELETE FROM t_student;

 

/*更新数据*/

UPDATE t_student SET name = ‘LNJ‘;

 

/*插入数据*/

 

 INSERT INTO t_student(age, score, name) VALUES (‘28‘, 100, ‘jonathan‘);

 INSERT INTO t_student(name, age) VALUES (‘lee‘, ‘28‘);

 INSERT INTO t_student(score) VALUES (100);

 

/*插入数据*/

INSERT INTO t_student(name, age, score) VALUES (‘lee‘, ‘28‘, 100);

 

/*添加主键*/

CREATE TABLE IF NOT EXISTS t_student (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, age INTEGER, score REAL);

/*添加主键*/

CREATE TABLE IF NOT EXISTS t_student (id INTEGER, name TEXT, age INTEGER, score REAL, PRIMARY KEY(id));

 

/*删除表*/

DROP TABLE IF EXISTS t_student;

 

/*创建表*/

CREATE TABLE IF NOT EXISTS t_student(id INTEGER , name TEXT, age , score REAL);

SQLite语句

标签:

原文地址:http://www.cnblogs.com/rankilau/p/4251613.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!