码迷,mamicode.com
首页 > 数据库 > 详细

MySQL第三课

时间:2019-11-07 23:25:27      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:rename   record   rds   add   表名   nbsp   ext   row   删除数据库   

首先创建一个数据库:

CREATE DATABASE ku;

Query OK, 1 row affected

查看一下是否有此数据库:

SHOW DATABASES;

+--------------------+
| Database           |
+--------------------+
| information_schema |
| ku                 |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set

使用此数据库:

 USE ku;
Database changed

创建数据表:

 CREATE TABLE biao(
    name VARCHAR(20),
    age INT(11),
    sex CHAR(11),
    love VARCHAR(11)
    );
Query OK, 0 rows affected

查看表结构:

DESC biao;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | YES  |     | NULL    |       |
| age   | int(11)     | YES  |     | NULL    |       |
| sex   | char(11)    | YES  |     | NULL    |       |
| love  | varchar(11) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set

修改表名:

ALTER TABLE biao RENAME biao1;

Query OK, 0 rows affected

 

修改字段和类型:

ALTER TABLE biao1 CHANGE SEX SEX1 CHAR(20);
Query OK, 0 rows affected
Records: 0  Duplicates: 0  Warnings: 0

用圆括号!!!!

 

再查看一边:

DESC biao1;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| name  | varchar(20) | YES  |     | NULL    |       |
| age   | int(11)     | YES  |     | NULL    |       |
| SEX1  | char(20)    | YES  |     | NULL    |       |
| love  | varchar(11) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set

修改字段的排列位置:

ALTER TABLE biao1 MODIFY NAME VARCHAR(20) AFTER SEX1;
Query OK, 0 rows affected
Records: 0  Duplicates: 0  Warnings: 0

查看:

DESC biao1;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| age   | int(11)     | YES  |     | NULL    |       |
| SEX1  | char(20)    | YES  |     | NULL    |       |
| NAME  | varchar(20) | YES  |     | NULL    |       |
| love  | varchar(11) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set

注意改的是大写出现的也是大写

加一个think字段:

ALTER TABLE biao1 ADD think VARCHAR (10) AFTER LOVE;
Query OK, 0 rows affected
Records: 0  Duplicates: 0  Warnings: 0

查看:

DESC biao1;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| age   | int(11)     | YES  |     | NULL    |       |
| SEX1  | char(20)    | YES  |     | NULL    |       |
| NAME  | varchar(20) | YES  |     | NULL    |       |
| love  | varchar(11) | YES  |     | NULL    |       |
| think | varchar(10) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
5 rows in set

删除think:

ALTER TABLE biao1 DROP think;
Query OK, 0 rows affected

Records: 0  Duplicates: 0  Warnings: 0

查看:

DESC biao1;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| age   | int(11)     | YES  |     | NULL    |       |
| SEX1  | char(20)    | YES  |     | NULL    |       |
| NAME  | varchar(20) | YES  |     | NULL    |       |
| love  | varchar(11) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
4 rows in set

删除此表:

DROP TABLE biao1;
Query OK, 0 rows affected

查看:

SHOW TABLES;
Empty set

删除数据库:

DROP DATABASE ku;
Query OK, 0 rows affected

查看:

SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set

 

 

 

MySQL第三课

标签:rename   record   rds   add   表名   nbsp   ext   row   删除数据库   

原文地址:https://www.cnblogs.com/zmh0227/p/11816250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!