CREATE ?TABLE student (
id ?INT(10) ?NOT NULL ?UNIQUE ?PRIMARY KEY ,
name ?VARCHAR(20) ?NOT NULL ,
sex ?VARCHAR(4) ,
birth ?YEAR,
department ?VARCHAR(20) ,
address ?VARCHAR(50)
);
创建score表。SQL代码如下:
CREATE ?TABLE score (
id ?INT(10) ?NOT NULL ?UNIQUE ?PRIMARY KEY ?AUTO_INCREMENT ,
stu_id ?INT(10) ?NOT NULL ,
c_name ?VARCHAR(20) ,
grade ?INT(10)
);
分别创建student表和score表:
create table student(id int(10) not null unique primary key,name varchar(20) not null,sex varchar(4),birth year,d
epartment varchar(20) not null,address varchar(50));
Query OK, 0 rows affected, 1 warning (0.04 sec)
create table score(id int(10) not null unique primary key auto_increment,stu_id int(10) not null,c_name varchar(2
0),grade int(10));
Query OK, 0 rows affected, 3 warnings (0.03 sec)
向student表插入记录的INSERT语句如下:
INSERT INTO student VALUES( 901,'张老大', '男',1985,'计算机系', '北京市海淀区');
INSERT INTO student VALUES( 902,'张老二', '男',1986,'中文系', '北京市昌平区');
INSERT INTO student VALUES( 903,'张三', '女',1990,'中文系', '湖南省永州市');
INSERT INTO student VALUES( 904,'李四', '男',1990,'英语系', '辽宁省阜新市');
INSERT INTO student VALUES( 905,'王五', '女',1991,'英语系', '福建省厦门市');
INSERT INTO student VALUES( 906,'王六', '男',1988,'计算机系', '湖南省衡阳市');
向score表插入记录的INSERT语句如下:
INSERT INTO score VALUES(NULL,901, '计算机',98);
INSERT INTO score VALUES(NULL,901, '英语', 80);
INSERT INTO score VALUES(NULL,902, '计算机',65);
INSERT INTO score VALUES(NULL,902, '中文',88);
向student表中填写数据:
mysql> INSERT INTO student VALUES( 901,'张老大', '男',1985,'计算机系', '北京市海淀区');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student VALUES( 902,'张老二', '男',1986,'中文系', '北京市昌平区');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student VALUES( 903,'张三', '女',1990,'中文系', '湖南省永州市');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO student VALUES( 904,'李四', '男',1990,'英语系', '辽宁省阜新市');
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO student VALUES( 905,'王五', '女',1991,'英语系', '福建省厦门市');
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO student VALUES( 906,'王六', '男',1988,'计算机系', '湖南省衡阳市');
Query OK, 1 row affected (0.01 sec)
向score表中填写数据:
mysql> INSERT INTO score VALUES(NULL,901, '计算机',98);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO score VALUES(NULL,901, '英语', 80);
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO score VALUES(NULL,902, '计算机',65);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO score VALUES(NULL,902, '中文',88);
Query OK, 1 row affected (0.01 sec)
2024年和2023年其没有满足要求的人选,所以无返回值。