-
Notifications
You must be signed in to change notification settings - Fork 0
/
mysql.txt
67 lines (48 loc) · 1.41 KB
/
mysql.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#显示数据库
show databases;
#判断是否存在数据库mydb,有的话先删除
drop database if exist mydb;
#创建数据库:mydb
create database mydb;
#删除数据库:mydb
drop database mydb;
#使用该数据库:mydb
use mydb;
#显示数据库中的表
show tables;
#先判断学生表是否存在,存在先删除
drop table if exist student;
#创建学生表
create table student(
id int auto_increment primary key,
name varchar(50),
sex varchar(50),
date varchar(50),
content varchar(100),
)default charset=utf8;
#删除学生表
drop table student;
#查看学生表的结构
describe student; #可以简写为 : desc student;
#学生表插入数据
insert into student values(null,'张三','男','1988-10-2','....');
#查询表中的数据
select * from student;
select id,name from student;
#修改某一条数据
update student set sex='男' where id=4;
#删除学生表中某条数据
delete from student where id=5;
#删除学生表中所有数据
delete from student;
# and 且
select * from student where date>'1988-1-2' and date<'1988-12-1';
# or 或
select * from student where date<'1988-11-2' or date>'1988-12-1';
#between
select * from student where date between '1988-1-2' and '1988-12-1';
#in 查询制定集合内的数据
select * from student where id in (1,3,5);
#排序 asc 升序 desc 降序
select * from student order_by id asc; #升序
select * from student order_by id desc; #降序