mysql数据库优化课程---6、mysql结构化查询语言有哪些
一、总结
一句话总结:主要分为四类
1.DCL 数据控制语言:比如rollback
2.DDL 数据定义语言:比如create
3.DML 数据操作语言:比如insert
4.DQL 数据查询语言:比如select
1.DCL 数据控制语言
1)grant
2)commit
3)rollback
2.DDL 数据定义语言
1)create
2)drop
3)alter
3.DML 数据操作语言
1)insert
2)delete
3)update
4.DQL 数据查询语言
1)select
2、mysql中G翻转表,更好显示?
G后面没有分号:比如desc delete from user where id=5G
3、为什么我们查找的时候用主键查找(找第五个用户使用id找还是用name找)?
速度非常快,比判断其它的,快太多了:用主键一般只用找一行
而如果用其它的,需要找 (他再哪行就要找多少行)
4、如何判断sql语句的检索效率?
desc字段:desc select * from user where id=5G:这里只是检测,并没有实际删除
5、mysql中的等于号是什么,赋值号是什么?
就是单的=,不是==
mysql中赋值: set @x=10;
6、mysql中的select是什么?
select就是mysql中的输出语句:set @x=10; select @x; 然后就得到10
比如:
set @x=10;
select @x;
然后就得到10
7、mysql中的逻辑运算符是什么?
and or between in
6.id>=3 and id<=7
select * from user where id>=3 and id<=7;
7.between 3 and 7
select * from user where id between 3 and 7;
8.id=3 or id=5 or id=6 or id=10
select * from user where id=3 or id=5 or id=6 or id=10;
二、内容在总结中
数据库操作:
1.DCL 数据控制语言
1)grant
2)commit
3)rollback
2.DDL 数据定义语言
1)create
2)drop
3)alter
3.DML 数据操作语言
1)insert
2)delete
3)update
4.DQL 数据查询语言
1)select
创建表语句:
mysql> create table user(
-> id int unsigned auto_increment primary key,
-> username varchar(50) not null,
-> password varchar(50) not null
-> );
表结构:
mysql> desc user;
+----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(50) | NO | | NULL | |
| password | varchar(50) | NO | | NULL | |
+----------+------------------+------+-----+---------+----------------+
3 rows in set (0.00 sec)
判断sql语句的检索效率:
desc select * from user where id=5;
增-insert:
insert into user(username,password) values('user1','123');
删-delete:
delete from user where id=5;
改-update:
update user set password='123' where id=2;
update user set username='user33',password='123' where id=3;
查-select:
select * from user;
#查询表中所有字段以及每个字段所对应的所有记录
where条件:
1.id>3
select * from user where id>3;
2.id>=3
select * from user where id>=3;
3.id<3;
select * from user where id<3;
4.id<=3;
select * from user where id<=3;
5.id>3 and id<7
select * from user where id>3 and id<7;
6.id>=3 and id<=7
select * from user where id>=3 and id<=7;
7.between 3 and 7
select * from user where id between 3 and 7;
8.id=3 or id=5 or id=6 or id=10
select * from user where id=3 or id=5 or id=6 or id=10;
9.in(3,5,6,10)
select * from user where id in(3,5,6,10);
2、mysql中G翻转表,更好显示?
G后面没有分号:比如desc delete from user where id=5G
rows为1表示只扫描了一行