第一步输入show databases;
第二部 use day15;
第三部创造一个along的表
mysql> create table along(
-> id int,
-> name varchar(20),
-> gender int(2),
-> birthday date,
-> email int (20),
-> remark varchar(50)
-> );
Query OK, 0 rows affected
+-----------------+
| Tables_in_day15 |
+-----------------+
| along |
| stydent |
+-----------------+
2 rows in set
第四部在查询一下 show tables;
第五部 在员工基本表上加age列;
alter table along add age int;
代码如上 along名字add 加age 后面定属性
第六部:查询 desc along;
效果图 这个就是表的效果图 上面的 写的代码都在里面
mysql> desc along;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| gender | int(2) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| email | int(20) | YES | | NULL | |
| remark | varchar(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
第7步 联系 修改email 的列长度为50的;
mysql>代码: alter table along modify email int(50);
mysql>查询一下: desc along;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| gender | int(2) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| email | int(50) | YES | | NULL | |
| remark | varchar(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+------------
已经从10变50了 email的
联系(3) 删除remark 的列
代码:alter table along drop remark;
mysql> 在查询一下:desc along;
+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| gender | int(2) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| email | int(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+-------------+------+-----+---------+-------+
就没有那个了列了:
联系4 列名 name 修改为 username;
代码:alter table along change name username varchar(20);
mysql>查询: desc along;
| id | int(11) | YES | | NULL | |
| username | varchar(20) | YES | | NULL | |
| gender | int(2) | YES | | NULL | |
| birthday | date | YES | | NULL | |
| email | int(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+----------+--
以上 就改了。。。name 改成 username。