Enter password: ***
Welcome to the MySQL monitor. Commands end with ; or \g.
create database class_db ;
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| class_db |
| da_database10 |
| mysql |
| test |
+——————–+
mysql> use class_db;
Database changed
mysql> create table admin ( id int(8) not null primary key auto_increment,
-> name varchar(30) ,
-> password varchar(30) );
Query OK, 0 rows affected (0.64 sec)
mysql> show tables;
+——————–+
| Tables_in_class_db |
+——————–+
| admin |
+——————–+
1 row in set (0.06 sec)
mysql> create table student( id varchar(50) not null primary key ,
-> name varchar(10) not null ,
-> password varchar(50) ,
-> jiguan varchar(10) not null ,
-> department varchar(10) ,
-> sex varchar(10) ,
-> mark int(11) ,
-> tel varchar(50) ,
-> e_mail varchar(50) );
Query OK, 0 rows affected (0.23 sec)
mysql> create table classes ( id varchar(50) not null ,
-> tea_id varchar(10) not null primary key ,
-> cour_id varchar(10) not null ,
-> room_id varchar(50) not null ,
-> cour_time varchar(10) not null );
Query OK, 0 rows affected (0.25 sec)
mysql> create table course ( id varchar(10) not null primary key ,
-> name varchar(20) not null ,
-> mark int(11) not null ,
-> prepare varchar(10) ,
-> dep varchar(10) );
Query OK, 0 rows affected (0.20 sec)
mysql> create table enrol ( stu_id varchar(50) not null primary key ,
-> class_id varchar(50) not null ,
-> accept tinyint(1) ,
-> score varchar(50) );
Query OK, 0 rows affected (0.25 sec)
mysql> create table teacher ( id varchar(10) not null ,
-> name varchar(50) not null ,
-> title varchar(50) not null ,
-> password varchar(50) not null );
Query OK, 0 rows affected (0.25 sec)
各表插入数据:
mysql> insert into admin values(1 , ‘limq’,1 ) ;
Query OK, 1 row affected (0.48 sec)
mysql> insert into student values(1 , ‘韩博’, 1, ‘山东’ , ‘机械系’, ‘女’, 9, 3317138,
‘123@qq.com’
) ;
Enter password: ***
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.68-community MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> use class_db;
Database changed
mysql> show tables;
+——————–+
| Tables_in_class_db |
+——————–+
| admin |
| classes |
| course |
| enrol |
| student |
| teacher |
+——————–+
6 rows in set (0.05 sec)
mysql> insert into student values(1 , ‘韩博’, 1, ‘山东’ , ‘机械系’, ‘女’, 9,
3317138,
123@qq.com
) ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
‘@qq.c
om )’ at line 1
mysql> insert into student values(1 , ‘韩博’, 1, ‘山东’ , ‘机械系’, ‘女’, 9,
3317138,
‘123@qq.com’
) ;
Query OK, 1 row affected (0.33 sec)
mysql> select * from student;
+—-+——+———-+——–+————+——+——+———+———-
–+
| id | name | password | jiguan | department | sex | mark | tel | e_mail
|
+—-+——+———-+——–+————+——+——+———+———-
–+
| 1 | 韩博 | 1 | 山东 | 机械系 | 女 | 9 | 3317138 |
123@qq.co
m |
+—-+——+———-+——–+————+——+——+———+———-
–+
1 row in set (0.09 sec)
mysql> insert into student values( 2 , ‘王强’, 1, ‘陕西’ , ‘机械系’, ‘男’, 5,
3317138,
‘124@qq.com’
) ;
Query OK, 1 row affected (0.13 sec)
mysql> select * from student;
+—-+——+———-+——–+————+——+——+———+———-
–+
| id | name | password | jiguan | department | sex | mark | tel | e_mail
|
+—-+——+———-+——–+————+——+——+———+———-
–+
| 1 | 韩博 | 1 | 山东 | 机械系 | 女 | 9 | 3317138 |
123@qq.co
m |
| 2 | 王强 | 1 | 陕西 | 机械系 | 男 | 5 | 3317138 |
124@qq.co
m |
+—-+——+———-+——–+————+——+——+———+———-
–+
2 rows in set (0.00 sec)
mysql> insert into student values( 3 , ‘张永’, 1, ‘河南’ , ‘电子系’, ‘男’, 0,
113317138,
‘125@qq.com’
) ;
Query OK, 1 row affected (0.14 sec)
mysql> select * from student;
+—-+——+———-+——–+————+——+——+———–+——–
—-+
| id | name | password | jiguan | department | sex | mark | tel | e_mail
|
+—-+——+———-+——–+————+——+——+———–+——–
—-+
| 1 | 韩博 | 1 | 山东 | 机械系 | 女 | 9 | 3317138 |
123@qq
.
com |
| 2 | 王强 | 1 | 陕西 | 机械系 | 男 | 5 | 3317138 |
124@qq
.
com |
| 3 | 张永 | 1 | 河南 | 电子系 | 男 | 0 | 113317138 |
125@qq
.
com |
+—-+——+———-+——–+————+——+——+———–+——–
—-+
3 rows in set (0.00 sec)
mysql> insert into classes values( 1 , 2, 1, 101 , Mon_1 ) ;
ERROR 1054 (42S22): Unknown column ‘Mon_1’ in ‘field list’
mysql> show columns from classes;
+———–+————-+——+—–+———+——-+
| Field | Type | Null | Key | Default | Extra |
+———–+————-+——+—–+———+——-+
| id | varchar(50) | NO | | NULL | |
| tea_id | varchar(10) | NO | PRI | NULL | |
| cour_id | varchar(10) | NO | | NULL | |
| room_id | varchar(50) | NO | | NULL | |
| cour_time | varchar(10) |