mysql常见的面试题----测试

1. 修改表中数据

命令:update 表名 set 字段=新值,... where 条件

mysql> update MyClass set name='Mary' where id=1;

2.在表中增加字段

命令:alter table 表名 add 字段 类型 其他;

例如:在表 MyClass 中添加了一个字段 passtest,类型为 int(4),默认值为 0

mysql> alter table MyClass add passtest int(4) default '0'

3.取表中前几行的数据

例如:查看表 MyClass 中前 2 行数据

mysql> select * from MyClass order by id limit 0,2;或者select * from MyClass order by id limit 2

4. 删除表中数据

命令:delete from 表名 where 表达式

例如:删除表 MyClass 中编号为 1 的记录

mysql> delete from MyClass where id=1;

5. 如果要查询不重复的记录,有时候可以用group by :

select id,name from user group by name;

6.多表联合查询:

外连接:左连接,右连接,完全外连接

       左连接:左表的数据都显示,右表显示与左表相等字段的连接

      右链接:右表的数据都显示,左表显示与右表相等字段的连接

      完全外连接:左表右表数据均显示

内连接:显示左表,右表条件相等的数据

猜你喜欢

转载自blog.csdn.net/ningmengbu_suan/article/details/107339101