目录
1.数据库建立
 2.增删改查
 3.视图建立:
1.数据库建立
mysql>
mysql> show databases;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| challenges                        |
| dvwa                              |
| hdcms                             |
| my                                |
| mysql                             |
| performance_schema                |
| security                          |
| #mysql50#sql                      |
| test                              |
| us                                |
| usualtoolcms-utf8-8.0-build181008 |
+-----------------------------------+
12 rows in set, 1 warning (0.00 sec)mysql> use mysql
Database changed
mysql> use mysql;
Database changed
mysql> show tables-> ;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
24 rows in set (0.11 sec)mysql> Create Database Bigpigfoot;
Query OK, 1 row affected (0.00 sec)mysql> show databases-> ;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| bigpigfoot                        |
| challenges                        |
| dvwa                              |
| hdcms                             |
| my                                |
| mysql                             |
| performance_schema                |
| security                          |
| #mysql50#sql                      |
| test                              |
| us                                |
| usualtoolcms-utf8-8.0-build181008 |
+-----------------------------------+
13 rows in set, 1 warning (0.00 sec)mysql> use bigpigfoot;
Database changed
mysql> show tables-> ;
Empty set (0.00 sec)mysql> create table Student(Sno CHAR(5) not NULL unique);
Query OK, 0 rows affected (0.47 sec)mysql> show tables;
+----------------------+
| Tables_in_bigpigfoot |
+----------------------+
| student              |
+----------------------+
1 row in set (0.00 sec)mysql> drop table student;
Query OK, 0 rows affected (0.00 sec)mysql> create table student(Sname VarCHAR(20)  unique,Ssex CHAR(1), Sage INT,Sdept CHAR(15))-> ;
Query OK, 0 rows affected (0.12 sec)mysql> show tables;
+----------------------+
| Tables_in_bigpigfoot |
+----------------------+
| student              |
+----------------------+
1 row in set (0.00 sec)mysql> create table Course(Cno CHAR(4) PRIMARY KEY,Cname VarCHAR(40),Cpno CHAR(4),Ccredit SMALLINT,FOREIGN KEY (Cpno) REFERENCES Course(Cno));
Query OK, 0 rows affected (0.34 sec)mysql> show tables;
+----------------------+
| Tables_in_bigpigfoot |
+----------------------+
| course               |
| student              |
+----------------------+
2 rows in set (0.00 sec)mysql> CREATE TABLE SC(->  Sno CHAR(5),->  Cno CHAR(3),->  Grade int,->  Primary key (Sno, Cno));
Query OK, 0 rows affected (0.12 sec)mysql>
mysql> ALTER TABLE Student ADD Scome DATETIME-> ;
Query OK, 0 rows affected (0.39 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> show tables;
+----------------------+
| Tables_in_bigpigfoot |
+----------------------+
| course               |
| sc                   |
| student              |
+----------------------+
3 rows in set (0.00 sec)mysql> select * from student-> ;
Empty set (0.00 sec)mysql> CREATE TABLE Student
mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Sname | varchar(20) | YES  | UNI | NULL    |       |
| Ssex  | char(1)     | YES  |     | NULL    |       |
| Sage  | int(11)     | YES  |     | NULL    |       |
| Sdept | char(15)    | YES  |     | NULL    |       |
| Scome | datetime    | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
5 rows in set (0.11 sec)ALTER TABLE Student ALTER COLUMN Sage SMALLINT;ALTER TABLE Student ALTER ' at line 1 
mysql> CREATE UNIQUE INDEX SCno ON SC(Sno ASC,Cno DESC);
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 'ASC??Cno DESC)' at line 1
mysql> CREATE UNIQUE INDEX Stusno ON Student(Sno);
ERROR 1072 (42000): Key column 'Sno' doesn't exist in table
mysql> ALTER TABLE Student ADD Sno datetime;
Query OK, 0 rows affected (0.15 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> CREATE UNIQUE INDEX Stusno ON Student(Sno);
Query OK, 0 rows affected (0.12 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> CREATE UNIQUE INDEX Coucno ON Course(Cno);
Query OK, 0 rows affected (0.11 sec)
Records: 0  Duplicates: 0  Warnings: 0mysql> desc student;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Sname | varchar(20) | YES  | UNI | NULL    |       |
| Ssex  | char(1)     | YES  |     | NULL    |       |
| Sage  | int(11)     | YES  |     | NULL    |       |
| Sdept | char(15)    | YES  |     | NULL    |       |
| Scome | datetime    | YES  |     | NULL    |       |
| Sno   | datetime    | YES  | UNI | NULL    |       |
+-------+-------------+------+-----+---------+-------+
6 rows in set (0.01 sec)mysql> DROP TABLE SC;
Query OK, 0 rows affected (0.00 sec)mysql> show tables;
+----------------------+
| Tables_in_bigpigfoot |
+----------------------+
| course               |
| student              |
+----------------------+
2 rows in set (0.00 sec)mysql> show databases;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| bigpigfoot                        |
| challenges                        |
| dvwa                              |
| hdcms                             |
| my                                |
| mysql                             |
| performance_schema                |
| s_t2                              |
| security                          |
| #mysql50#sql                      |
| test                              |
| us                                |
| usualtoolcms-utf8-8.0-build181008 |
+-----------------------------------+
14 rows in set, 1 warning (0.46 sec)mysql> create database S_T3;
Query OK, 1 row affected (0.00 sec)mysql> DROP database S_T3;
Query OK, 0 rows affected (0.27 sec)mysql> create database S_T3;
Query OK, 1 row affected (0.00 sec)mysql> use S_T3;
Database changed
mysql> create table Student(Sno char(5) unique not NULL,Sname char(20) unique,Sage int,Sinst char(20));
Query OK, 0 rows affected (0.38 sec)mysql> create table Institute(Sinst char(20) unique,Ilocation char(20),Icall char(20));
Query OK, 0 rows affected (0.10 sec)mysql> insert into Student values('1913','daming',20,'ruanjian');
Query OK, 1 row affected (0.00 sec)mysql> insert into Student values('1914','lili',22,'dashuju');
Query OK, 1 row affected (0.00 sec)mysql> insert into Student values('1915','王国煜',23,'软件学院');
Query OK, 1 row affected, 4 warnings (0.08 sec)mysql> insert into institute values('ruanjian','田园','123456');
Query OK, 1 row affected, 2 warnings (0.00 sec)mysql> insert into institute values('软件','田园','123456');
Query OK, 1 row affected, 4 warnings (0.00 sec)mysql> insert into institute values('dashuju','东区','456789');
Query OK, 1 row affected, 2 warnings (0.00 sec)mysql> show databases-> ;
+-----------------------------------+
| Database                          |
+-----------------------------------+
| information_schema                |
| bigpigfoot                        |
| challenges                        |
| dvwa                              |
| hdcms                             |
| my                                |
| mysql                             |
| performance_schema                |
| s_t2                              |
| s_t3                              |
| security                          |
| #mysql50#sql                      |
| test                              |
| us                                |
| usualtoolcms-utf8-8.0-build181008 |
+-----------------------------------+
15 rows in set, 1 warning (0.00 sec)mysql> show tables;
+----------------+
| Tables_in_s_t3 |
+----------------+
| institute      |
| student        |
+----------------+
2 rows in set (0.00 sec)mysql> desc institute;
+-----------+----------+------+-----+---------+-------+
| Field     | Type     | Null | Key | Default | Extra |
+-----------+----------+------+-----+---------+-------+
| Sinst     | char(20) | YES  | UNI | NULL    |       |
| Ilocation | char(20) | YES  |     | NULL    |       |
| Icall     | char(20) | YES  |     | NULL    |       |
+-----------+----------+------+-----+---------+-------+
3 rows in set (0.34 sec)mysql> desc student;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| Sno   | char(5)  | NO   | PRI | NULL    |       |
| Sname | char(20) | YES  | UNI | NULL    |       |
| Sage  | int(11)  | YES  |     | NULL    |       |
| Sinst | char(20) | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
4 rows in set (0.01 sec)mysql>
2.增删改查

 
 
 
 
 
 
 
3.视图建立:

 
 
整理了一下过去所学的东西…