常用的SQL(structured query language 结构化查询语言)语句
1,创建表
CREATE 创建
TABLE 表
PRIMARYKEY 主键,唯一标示符;
AUTOINCREMENT 自动增长
NOTNULL 非空
UNIQUE 唯一的
CREATE TABLE Teacher1 (teacher_id INTEGER PRIMARYKEY AUTOINCREMENT NOT NULL UNIQUE, teacher_name TEXT, teacher_sex BOOL EAN)
CREATE TABLE Teacher2 (teacher_id INTEGER PRIMARYKEY AUTOINCREMENT, teacher_name TEXT, teacher_sex BOOL EAN)
CREATE TABLEif not exists student (id int primarykey not null,name text,age int)
2, 删除表
DROP 丢弃 扔到
DROP TABLE Teacher1
3,给表添加列
ALTER 改变 修改
ALTER TABLE Teacher2 ADD teacher_age INT EGER
4,插入数据
INSERT INTO Teacher VALUES(1 ,'zhangsan' ,1)
INSERT INTO Students (name ,sex) VALUES ('zhangsan' ,0)
5,查询数据
SELECT 查询
* 全部
FROM
SELECT * FROM Students
SELECT * FROM Students WHERE number<10
SELECT * FROM Students WHERE number<10 OR sex=1
SELECT * FROM Students WHERE number<10 AND number>5
like 匹配
SELECT * FROM Students WHERE name like '%zhang%'
SELECT * FROM Students WHERE name like 'zhang_'
LIMIT 限制
从第六条开始往后的15条
SELECT * FROM Students LIMIT 5,15
6,修改数据
UPDATE 更新
set 设置
UPDATE Students set name = 'lisi' ,sex = 1 where number < 10 AND number>5
7,删除数据
DELETE 删除
DELETE FROM Students WHERE number > 25
delete from people_test where people_id <> 3
等价于
delete from people_test where people_id != 3