美文网首页
查看 表的结构 和 生成表的SQL语句

查看 表的结构 和 生成表的SQL语句

作者: MrTricker | 来源:发表于2018-10-13 16:00 被阅读0次

    一、查看表结构

     mysql> desc `table_name`;
    
    +-------------+--------------+------+-----+---------+----------------+
    | Field       | Type         | Null | Key | Default | Extra          |
    +-------------+--------------+------+-----+---------+----------------+
    | id          | int(11)      | NO   | PRI | NULL    | auto_increment |
    | choice_text | varchar(200) | NO   |     | NULL    |                |
    | votes       | int(11)      | NO   |     | NULL    |                |
    | question_id | int(11)      | NO   | MUL | NULL    |                |
    +-------------+--------------+------+-----+---------+----------------+
    4 rows in set (0.02 sec)
    

    二、查看生成表的 SQL 语句

    mysql> show create table `table_name`;
    
    +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | Table        | Create Table                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
    +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    | table_name | CREATE TABLE `table_name` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `choice_text` varchar(200) NOT NULL,
      `votes` int(11) NOT NULL,
      `question_id` int(11) NOT NULL,
      PRIMARY KEY (`id`),
      KEY `table_name_question_id_c5b4b260_fk_other_table_name_id` (`question_id`),
      CONSTRAINT `table_name_question_id_c5b4b260_fk_other_table_name_id` FOREIGN KEY (`question_id`) REFERENCES `other_table_name` (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |
    +--------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    

    相关文章

      网友评论

          本文标题:查看 表的结构 和 生成表的SQL语句

          本文链接:https://www.haomeiwen.com/subject/vrboaftx.html