修改字段类型和修饰符
>alter table members modify qq int(10) not null;
>alter table members modify qq int(10) after tel; //字段排序
>alter table members modify qq int(10) first; // 字段排序
修改字段名称、字段类型、修饰符
>alter table members change qq qq int(20) after tel;
>alter table members change qq addr char(20) first;
修改表名称
>alter table members rename t1;
------------------------------------------------
往表里添加记录
> insert into t1(id,name,qq) values(1,"Lucy",773765);
> insert into t1 set id=2,name="John",qq=6656998;
> insert into t1 value(3,"Monica",765687);
查看
> select * from t1;
+----+--------+---------+
| id | name | qq |
+----+--------+---------+
| 1 | Lucy | 773765 |
| 2 | John | 6656998 |
| 3 | Monica | 765687 |
+----+--------+---------+
多条记录一起添加:
> insert into t1 values(4,"Jean",6636677),(5,"Nana",378998),(6,"Hebe",8457839);
条件查询
>select name,qq from t1 where id=3;
>select name,qq from t1 where id=3 or id=4;
查看现在登录的帐号
>select user();
查看日期
>select now();
查看记录个数
>select count(*) from xueke;
查看字段总和
>select sum(math) from xueke;
查看字段平均值
>select avg(math) from xueke;
查看字段最大值
>select max(math) from xueke;
查看字段最小值
>select min(math) from xueke;
根据条件查看
>select count(*) from xueke where gender='male';
分组查看
>select name,gender,count(*) from xueke group by gender;
排序查看
>select * from xueke order by math; // 升序
>select * from xueke order by math desc; // 降序
显示指定的几行
mysql> select * from xueke order by phy desc limit 0,3; // 排序之后显示前三条记录 0表示第一条记录
mysql> select * from xueke order by phy desc limit 3; // 另一种写法
mysql> select * from xueke order by phy desc limit 1,2; // 从第2条记录开始取,取2条记录