在武汉北大青鸟鲁广校区学习软件开发,常常用到mysql数据库,说不定这条数据就是从MySQL读的哦。
1.create
database
school//创建数据库
2.
show
databases
//查看数据库
3.
use
school
//使用创建的数据库
4.
create
table
students
(
s_no
int
,name
varchar(20),gender
varchar(10),birthday
datetime,image
blob
,address
varchar(50),
c_no
int,primary
key
(s_no,c_no)
)
//建students表
5.
create
table
classes(c_no
int,name
varchar(20)
,
class_adviser
varchar(20)
,foreign
key(c_no)
REFERENCES
students(c_no))
//建classes表
6.
insert
into
students(s_no,name,gender,birthday,image,address,c_no)
values(1,'Sally','FM','1987-1-2',null,'aaaaa',1)
7.
insert
into
students(s_no,name,gender,birthday,image,address,c_no)
values(2,'Nicholas','M','1985-8-8',Null,'bbbbb',1)
8.
insert
into
students(s_no,name,gender,birthday,image,address,c_no)
values(3,'Jason','M','1988-5-19',Null,'ccccc',2)
9.
insert
into
students(s_no,name,gender,birthday,image,address,c_no)
values(4,'Jamile','M','1979-2-5',Null,'ddddd',2)
10.
insert
into
classes
(c_no,name,class_adviser)
values
(1,'Class1','Mike')
11.
insert
into
classes
(c_no,name,class_adviser)
values
(2,'Class2','Andy')
12.
select
a.*
from
students
a,
classes
b
where
a.c_no
in
(select
b.c_no
from
classes
b
where
b.class_adviser
=
'Mike')
and
a.c_no
=
b.c_no
//查数据
或者
select
students.s_no,
students.name,
students.gender,
students.birthday,
students.image,
students.address,
students.c_no
from
students,
classes
where
students.c_no
in
(select
c_no
from
classes
where
class_adviser
=
'Mike')
and
students.c_no
=
classes.c_no
卢旭
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)