第2次作业-SQL语句的基本使用

1.使用SQL语句创建数据库studentsdb

mysql> create database studentsdb;
Query OK, 1 row affected (0.01 sec)
image

2.使用SQL语句选择studentsdb为当前使用数据库。

mysql> use studentsdb;
Database changed
image

3.使用SQL语句在studentsdb数据库创建数据表student_info、curriculum、grade,。

创建数据表student_info
mysql> create table student_info(
    -> 学号 char(4) not null primary key,
    -> 姓名 char(8) not null ,
    -> 性别 char(2),
    -> 出生日期 date,
    -> 家族住址 varchar(50)
    -> );
    

image
创建数据表curriculum

mysql> create table curriculum(
    -> 课程编号 char(4) not null primary key,
    -> 课程名称 varchar(50),
    -> 学分 int);
Query OK, 0 rows affected (0.02 sec)

image
创建数据表grade

mysql> create table grade(
   -> 学号 char(4) not null,
    -> 课程编号 char(4)not null,
   -> 分数 int);`
Query OK, 0 rows affected (0.04 sec)

mysql> alter table grade`
    -> ADD PRIMARY KEY (学号, 课程编号);
Query OK, 0 rows affected (0.04 sec)
Records: 0  Duplicates: 0  Warnings: 0

image

4.使用SQL语句INSERT向studentsdb数据库的student_info、curriculum、grade表插入数据。

student_info表的数据

mysql> insert into student_info(学号,姓名,性别,出生日期,家族住址)
    -> values('0001','张青平','男','2000-10-01','衡阳市东风路77号'),
    ->('0002','刘东阳','男','1998-12-09','东阳市八一北路33号'),
    ->('0003','马晓夏','女','1995-05-12','长岭市五一路763号'),
    ->('0004','钱忠理','男','1994-09-23','滨海市洞庭大道279号'),
    -> ('0005','孙海洋','男','1995-04-03','长岛市解放路27号'),
    -> ('0006','郭小斌','男','1997-11-10','南山市红旗路113号'),
    -> ('0007','肖月玲','女','1996-12-07','东方市南京路11号'),
    -> ('0008','张玲珑','女','1997-12-24','滨江市新建路97号');
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

image
curriculum表的数据

mysql> insert into curriculum(课程编号,课程名称,学分)
    -> values('0001','计算机应用基础','2'),
    -> ('0002','C语言程序设计','2'),
    -> ('0003','数据库原理及应用','2'),
    -> ('0004','英语','4');
Query OK, 4 rows affected (0.02 sec)
Records: 4  Duplicates: 0  Warnings: 0

image

grade表插入数据

mysql> insert into grade(学号,课程编号,分数)
    -> values('0001','0001','80'),
    -> ('0001','0002','91'),
    -> ('0001','0003','88'),
    -> ('0001','0004','85'),
    -> ('0001','0005','77'),
    -> ('0002','0001','73'),
    -> ('0002','0002','68'),
    -> ('0002','0003','80'),
    -> ('0002','0004','79'),
    -> ('0002','0005','73'),
    -> ('0003','0001','84'),
    -> ('0003','0002','92'),
    -> ('0003','0003','81'),
    -> ('0003','0004','82'),
    -> ('0003','0005','75');
Query OK, 15 rows affected (0.01 sec)
Records: 15  Duplicates: 0  Warnings: 0

image

posted @ 2023-09-19 16:13  Sss~~  阅读(120)  评论(0)    收藏  举报