SQL一般分为DQL,DML,DDL:
DQL:数据查询语句,SELECT
DML:数据操作语言,INSERT,UPDATE,DELETE
DDL:数据定义语言,主要用于创建 删除,以及修改表 索引等数据库对象语言
DDL:
创建
CREATE TABLE table_name{
col01_name data_type,
col02_name data_type,
col03_name data_type,
col04_name data_type,
}
删除
DROP TABLE table_name
DML:
插入:INSERT INTO student VALUES(1, "zhangsan", 14);
更新:UPDATE student SET age = 15;
删除:DELETE FROM student WHERE no = 3;
查询:
SELECT* FROM student
过滤条件:SELECT* FROM student where age>= 15;
排序:SELECT* FROM student (where ...)ORDER BY age;
分组查询:SELECT age,count(*) FROM student GROUP BY age;
表join 多表关联查询:SELECT student_name, class_name FROM student, class WHERE student.class_no = class.no;
其他SQL语句:
INSERT INTO...SELECT 可以把数据从一张表插入到另一张表中
INSERT INTO student_bak SELECT * FROM student;
UNION语句:
SELECT * FROM student WHERE no = 1 UNION SELECT * FROM student_bak where no = 2;
TRUNCATE TABLE 语句:清空表内容
TRUNCATE TABLE student_bak;