一、创建一个数据库 “db_classes”
mysql> create database db_classes;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| db_classes |
| information_schema |
| mysql |
| performance_schema |
| sys |
| user |
+--------------------+
6 rows in set (0.00 sec)
二、创建一行表`db_hero`
mysql> use db_classes;
Database changedmysql> desc db_hero;
+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| id | int | YES | | NULL | |
| name | varchar(100) | YES | | NULL | |
| nickname | varchar(100) | YES | | NULL | |
| age | int | YES | | NULL | |
| gebder | varchar(100) | YES | | NULL | |
| address | varchar(100) | YES | | NULL | |
| weapon | varchar(100) | YES | | NULL | |
| word | varchar(100) | YES | | NULL | |
| types | varchar(100) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+
9 rows in set (0.00 sec)
三、将四大名著里面的常见任务插入表中
mysql> insert into db_hero values();(括号内填写表信息)
四、添加约束
原本表单:
mysql> desc db_hero;
添加约束:
mysql> alter table db_hero modify name varchar(255) not null unique ;
mysql> alter table db_hero modify nickname varchar(255) unique;
mysql> alter table db_hero modify age int default 18;
mysql> alter table db_hero modify address varchar(255) not null;
mysql> alter table db_hero modify weapon varchar(50) not null;