INSERT TAB_NAME(字段名称..) VALUES(值....) WHERE (添加条件) UPDATE TAB_NAME SET 字段名称= UPDATE user SET age=25 WHERE id=1; DELETE FORM TAB_NAEM WHERE (添加条件) DELETE FORM user WHERE age>=24 //删除数据,不加条件,删除所有数记录,AUTO_INCREMENT不会重置 SHOW CREAEAT TABLE TBA_NAME //查询表条件 修改表结构 ALTER ALTER TABLE TAB_NAME AUTO_INCREMENT=1 TAUNCATE TAB_NAME彻底清空精数据 查询记录 SELECT FORM TAB_NAE [WHERE 条件] [GROUP BY (COL_NAME) HAVING 二次筛选] [GRDER BY (COL_NAME) BY (ASC|DESC)] [LIMT限制结果集的显示条数] SELECT * FROM TAB_NAME //查询表中所有字段 SELECT username,addr,age FROM TAB_NAME //查询指定字段 SELECT * FORM king.user //查询king下的user表 给字段起别名 SELECT 字段名 AS 别名 FROM TBA_NAME SELECT id AS '编号',username AS '用户名' FROM user; 给数据表取别名 SELECT TAB_NAME FORM TAB_NAME AS 别名 SELECT id,userName,age FROM user AS u 表名.字段名 SELECT TAB_NAME.COL.NAME FROM TBA_NAME; SELECT user1.id,user1.userName,user1.age FROM user1 条件查询 比较运算符 SELECT id,username,age FROM user WHERE id=5; ALTER TABLE user1 ADD 添加的字段 VARCHAR(100) 查询用户userDesc 为null的用户 SELECT id,userName,age,userDesc FROM user1 WHERE userDesc<=>NULL 检测null (IS NOT NULL) SELECT id,userName,userDesc FROM user WHERE userDes IS NULL 查询范围 BETWEEN AND | NOT BETWEEN START AND END 舍近求远年龄18-30的用户 SELECT id,userName,age,sex FROM age BETWEEN 18 AND 30; 查询指定集合 IN SELECT id,uerName,age FROM user1 WHERE id IN (1,3,5,7,29,45,78) 逻辑运算符AND RO SELECT id,userName,age,sex FROM user1 WHERE sex='男' AND age>20; SELECT id,userName,age,sex FROM user1 WHERE id='1' AND 匹配字符 模糊查询 like SELECT id,userName,age,sex FROM suer1 WEERE username LIKE 'king'; 结合通配符查询 %匹配多个, _匹配单个占位符 SELECT id,userName,age,sex FROM user1 WHERE username LIKE '%三%' 查询以风为结尾的用户 SELECT id,userName,age,sex FROM user1 WHERE username LIKE '%风' 查询以风为开头的用户 SELECT id,userName,age,sex FROM user1 WHERE username LIKE '风%' 查询三位的用户 SELECT id,userName,age,sex FROM user1 WHERE username LIKE '___'