(1)添加字段
alter table 表名 add 列名 类型 demo:alter table students add birthday datetime;
(2)修改字段------重命名版
alert table 表名 change 原名 新名 类型及约束 demo:alter table syudents change birthday birth datetime not null;
(3)修改字段------不重命名
alter table 表名 modify 列名 类型及约束 demo : alter table students modify birth date nout noll;
2.范围查询
in:表示在一个非连续的范围内 between … and …:表示在一个连续的范围内
查询编号是1或3或8的学生 select * from students where id in(1,3,8); 查询编号为3至8的学生 select * from students where id between 3 and 8; 查询编号是3至8的男生 select * from students where (id between 3 and 8) and gender=1;优先级
优先级由高到低的顺序为:小括号,not,比较运算符,逻辑运算符 and比or先运算,如果同时出现并希望先算or,需要结合()使用
排序 语法说明:
将行数据按照列1进行排序,如果某些行 列1 的值相同时,则按照 列2 排序,以此类推 asc从小到大排列,即升序 desc从大到小排序,即降序 默认按照列值从小到大排列(即asc关键字)
SQL语句的执行顺序:
–第一步:执行FROM –第二步:WHERE条件过滤 –第三步:GROUP BY分组 –第四步:执行SELECT投影列 –第五步:HAVING条件过滤 –第六步:执行ORDER BY 排序