常用的SQL(structured query language 結(jié)構(gòu)化查詢語(yǔ)言)語(yǔ)句
1兵拢,創(chuàng)建表
CREATE 創(chuàng)建
TABLE 表
PRIMARYKEY 主鍵,唯一標(biāo)示符揭朝;
AUTOINCREMENT 自動(dòng)增長(zhǎng)
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,插入數(shù)據(jù)
INSERT INTO Teacher VALUES(1 ,'zhangsan' ,1)
INSERT INTO Students (name ,sex) VALUES ('zhangsan' ,0)
5,查詢數(shù)據(jù)
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 限制
從第六條開(kāi)始往后的15條
SELECT * FROM Students LIMIT 5,15
6,修改數(shù)據(jù)
UPDATE 更新
set 設(shè)置
UPDATE Students set name = 'lisi' ,sex = 1 where number < 10 AND number>5
7,刪除數(shù)據(jù)
DELETE 刪除
DELETE FROM Students WHERE number > 25
delete from people_test where people_id <> 3
等價(jià)于
delete from people_test where people_id != 3