1.启动Mysql服务
net start mysql
2.进入mysql环境中,由于自己没有设置密码,直接回车进入即可(要将bin加入到环境变量path中)
mysql -u root -p
3.创建一个数据库
create database db_test default character set utf8 collate utf8_general_ci;
显示数据库:show databases;
使用某个数据库:use db_test;
显示该数据库的字符的编码:show variables like "%char%";
查看某个表的结构:desc student;
向student表中插入数据:4个字段,SId(学生ID),Sname(学生姓名),Sage(学生年龄),Ssex(学生性别)
insert into Student values('01' , '赵雷' , '1990-01-01' , '男');
insert into Student values('02' , '钱电' , '1990-12-21' , '男');
insert into Student values('03' , '孙风' , '1990-12-20' , '男');
insert into Student values('04' , '李云' , '1990-12-06' , '男');
insert into Student values('05' , '周梅' , '1991-12-01' , '女');
insert into Student values('06' , '吴兰' , '1992-01-01' , '女');
insert into Student values('07' , '郑竹' , '1989-01-01' , '女');
insert into Student values('09' , '张三' , '2017-12-20' , '女');
insert into Student values('10' , '李四' , '2017-12-25' , '女');
insert into Student values('11' , '李四' , '2012-06-06' , '女');
insert into Student values('12' , '赵六' , '2013-06-13' , '女');
insert into Student values('13' , '孙七' , '2014-06-01' , '女');
查询student表中的数据:select * from student;
同理:建立Teacher表,2个字段,TId(教师id),Tname(教师姓名)
create table Teacher(TId varchar(10),Tname varchar(10),PRIMARY key (Tid));
insert into Teacher values('01' , '张三');
insert into Teacher values('02' , '李四');
insert into Teacher values('03' , '王五');
建立课程表Course:
3个字段,CId(课程id),Cname(课程名称),TId(教师id)
create table Course(CId varchar(10),Cname nvarchar(10),TId varchar(10),PRIMARY KEY(CId));
insert into Course values('01' , '语文' , '02');
insert into Course values('02' , '数学' , '01');
insert into Course values('03' , '英语' , '03');
建立成绩表Score:4个字段,skey(由于没有不重复的字段,因此创建了主键字段),SId(学生id),CId(课程ID),score(学生成绩)
create table Score(skey int ,SId varchar(10),CId varchar(10),Scoreore decimal(18,1),PRIMARY key(skey));
insert into Score values('1','01' , '01' , 80);
insert into Score values('2','01' , '02' , 90);
insert into Score values('3','01' , '03' , 99);
insert into Score values('4','02' , '01' , 70);
insert into Score values('5','02' , '02' , 60);
insert into Score values('6','02' , '03' , 80);
insert into Score values('7','03' , '01' , 80);
insert into Score values('8','03' , '02' , 80);
insert into Score values('9','03' , '03' , 80);
insert into Score values('10','04' , '01' , 50);
insert into Score values('11','04' , '02' , 30);
insert into Score values('12','04' , '03' , 20);
insert into Score values('13','05' , '01' , 76);
insert into Score values('14','05' , '02' , 87);
insert into Score values('15','06' , '01' , 31);
insert into Score values('16','06' , '03' , 34);
insert into Score values('17','07' , '02' , 89);
insert into Score values('18','07' , '03' , 98);