1 """"""
2 """表:类似文件夹"""
3 '''
4 在创建表的时候 需要 先 指定 库;5 SQL语句: use 库名 # 指定库名6
7 例:8 mysql> use db119 Database changed10
11 SQL语句: select database(); # 查询当前所在的库12 mysql> select database();13 +------------+14 | database() |15 +------------+16 | db11 |17 +------------+18 1 row in set (0.00 sec)19 '''
20 """
21 # 增22 SQL语句:create table userinfo(id int,name char);23 例:24 mysql> create table userinfo(id int,name char);25 Query OK, 0 rows affected (0.47 sec)26
27 # 查28 SQL语句:29 show tables; # 查看某库下所有的表30
31 例:32 mysql> show tables;33 +----------------+34 | Tables_in_db11 |35 +----------------+36 | userinfo |37 +----------------+38 1 row in set (0.00 sec)39
40 SQL语句:41 show create table userinfo; # 查看指定表42 例:43 mysql> show create table userinfo;44 +----------+---------------------------------------------------------------------------------------------------------------------------+45 | Table | Create Table |46 +----------+---------------------------------------------------------------------------------------------------------------------------+47 | userinfo | CREATE TABLE `userinfo` (48 `id` int(11) DEFAULT NULL,49 `name` char(1) DEFAULT NULL50 ) ENGINE=InnoDB DEFAULT CHARSET=utf8 |51 +----------+---------------------------------------------------------------------------------------------------------------------------+52 1 row in set (0.00 sec)53
54 SQL语句:55 # 查询表结构 desc userinfo; <==> describe userinfo56 例:57 mysql> desc userinfo;58 +-------+---------+------+-----+---------+-------+59 | Field | Type | Null | Key | Default | Extra |60 +-------+---------+------+-----+---------+-------+61 | id | int(11) | YES | | NULL | |62 | name | char(1) | YES | | NULL | |63 +-------+---------+------+-----+---------+-------+64 2 rows in set (0.01 sec)65
66 mysql> describe userinfo;67 +-------+---------+------+-----+---------+-------+68 | Field | Type | Null | Key | Default | Extra |69 +-------+---------+------+-----+---------+-------+70 | id | int(11) | YES | | NULL | |71 | name | char(1) | YES | | NULL | |72 +-------+---------+------+-----+---------+-------+73 2 rows in set (0.01 sec)74 # 改75 SQL语句:alter table userinfo modify name char(32) # 修改指定表的指定行的字节数76
77 例:78 mysql> alter table userinfo modify name char(32);79 Query OK, 0 rows affected (0.62 sec)80 Records: 0 Duplicates: 0 Warnings: 081
82 验证:83 mysql> desc userinfo;84 +-------+----------+------+-----+---------+-------+85 | Field | Type | Null | Key | Default | Extra |86 +-------+----------+------+-----+---------+-------+87 | id | int(11) | YES | | NULL | |88 | name | char(32) | YES | | NULL | |89 +-------+----------+------+-----+---------+-------+90 2 rows in set (0.01 sec)91
92 # 删93 SQL语句:drop table userinfo; # 删掉指定表94 例:95 mysql> drop table userinfo;96 Query OK, 0 rows affected (0.15 sec)97
98 验证:99 mysql> show create table userinfo;100 ERROR 1146 (42S02): Table 'db11.userinfo' doesn't exist101 """