1、显示(查看)创建的数据表的结构。
mysql> SHOW COLUMNS FROM tdb_goods_cates;
+---------- -+-------------------- --+------+-----+---------+--------------- -+
| Field | Type | Null | Key | Default | Extra |
+----------- +--------------------- -+------+-----+---------+-------------- --+
| cate_id | smallint(5) unsigned | NO | PRI | NULL |auto_increment|
|cate_name| varchar(40) | YES | | NULL | |
+----------- +---------------------- +----- +-----+---------+--------------- -+
2 rows in set (0.01 sec)
2、查询数据表已经写入的所有记录
mysql> SELECT * FROM tdb_goods_cates;
+---------+---------------+
| cate_id | cate_name |
+---------+---------------+
| 1 | 台式机 |
| 2 | 平板电脑 |
| 3 | 服务器/工作站|
| 4 | 游戏本 |
| 5 | 笔记本 |
| 6 | 笔记本配件 |
| 7 | 超级本 |
| 8 | 路由器 |
| 9 | 交换机 |
| 10 | 网卡 |
+---------+---------------+
10 rows in set (0.00 sec)
3、修改数据表tdb_goods,把goods_cate改成cate_id,并把类型改成SMALLINT UNSIGNED NOT NULL,
把brand_name改成 brand_id ,并把类型改成SMALLINT UNSIGNED NOT NULL。
ALTER TABLE tdb_goods
CHANGE goods_cate cate_id SMALLINT UNSIGNED NOT NULL,
CHANGE brand_name brand_id SMALLINT UNSIGNED NOT NULL;
4、查看数据库的创建命令
mysql> SHOW CREATE TABLE test;
+-------+----------------------------------------------------------------------
-------------------------------------------------------------------------------
---------------------------------------+
| Table | Create Table
|
+-------+----------------------------------------------------------------------
-------------------------------------------------------------------------------
---------------------------------------+
| test | CREATE TABLE `test` (
`id` tinyint(3) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------
-------------------------------------------------------------------------------
---------------------------------------+