查看mysql表结构和表创建语句的方法

来源:互联网 发布:申请淘宝店铺要多久 编辑:程序博客网 时间:2024/04/30 15:24
  1. http://blog.csdn.net/business122/article/details/7531291 

  2. 查看mysql表结构的方法有三种:  
  3. 1、desc tablename;  
  4. 例如:  
  5. 要查看jos_modules表结构的命令:  
  6. desc jos_modules;  
  7. 查看结果:  
  8. mysql> desc jos_modules;  
  9. +------------------+---------------------+------+-----+---------------------+----------------+  
  10. | Field            | Type                | Null | Key | Default             | Extra          |  
  11. +------------------+---------------------+------+-----+---------------------+----------------+  
  12. | id               | int(11)             | NO   | PRI | NULL                | auto_increment |  
  13. | title            | text                | NO   |     | NULL                |                |  
  14. | content          | text                | NO   |     | NULL                |                |  
  15. | ordering         | int(11)             | NO   |     | 0                   |                |  
  16. | position         | varchar(50)         | YES |     | NULL                |                |  
  17. | checked_out      | int(11) unsigned    | NO   |     | 0                   |                |  
  18. | checked_out_time | datetime            | NO   |     | 0000-00-00 00:00:00 |                |  
  19. | published        | tinyint(1)          | NO   | MUL | 0                   |                |  
  20. | module           | varchar(50)         | YES | MUL | NULL                |                |  
  21. | numnews          | int(11)             | NO   |     | 0                   |                |  
  22. | access           | tinyint(3) unsigned | NO   |     | 0                   |                |  
  23. | showtitle        | tinyint(3) unsigned | NO   |     | 1                   |                |  
  24. | params           | text                | NO   |     | NULL                |                |  
  25. | iscore           | tinyint(4)          | NO   |     | 0                   |                |  
  26. | client_id        | tinyint(4)          | NO   |     | 0                   |                |  
  27. | control          | text                | NO   |     | NULL                |                |  
  28. +------------------+---------------------+------+-----+---------------------+----------------+  
  29. 2、show create table tablename;  
  30. 例如:  
  31. 要查看jos_modules表结构的命令:  
  32. show create table jos_modules;  
  33. 查看结果:  
  34. mysql> show create table jos_modules;  
  35. jos_modules | CREATE TABLE `jos_modules` (  
  36. `id` int(11) NOT NULL AUTO_INCREMENT,  
  37. `title` text NOT NULL,  
  38. `content` text NOT NULL,  
  39. `ordering` int(11) NOT NULL DEFAULT '0',  
  40. `position` varchar(50) DEFAULT NULL,  
  41. `checked_out` int(11) unsigned NOT NULL DEFAULT '0',  
  42. `checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',  
  43. `published` tinyint(1) NOT NULL DEFAULT '0',  
  44. `module` varchar(50) DEFAULT NULL,  
  45. `numnews` int(11) NOT NULL DEFAULT '0',  
  46. `access` tinyint(3) unsigned NOT NULL DEFAULT '0',  
  47. `showtitle` tinyint(3) unsigned NOT NULL DEFAULT '1',  
  48. `params` text NOT NULL,  
  49. `iscore` tinyint(4) NOT NULL DEFAULT '0',  
  50. `client_id` tinyint(4) NOT NULL DEFAULT '0',  
  51. `control` text NOT NULL,  
  52. PRIMARY KEY (`id`),  
  53. KEY `published` (`published`,`access`),  
  54. KEY `newsfeeds` (`module`,`published`)  
  55. ) ENGINE=MyISAM AUTO_INCREMENT=145 DEFAULT CHARSET=utf8  
  56. 3、use information_schema;select * from columns where table_name='tablename'  
  57. 例如:  
  58. 要查看jos_modules表结构的命令:  
  59. use information_schema;  
  60. select * from columns where table_name='jos_modules';  
  61. 查看结果:  
  62. 略。  
  63. 如果要查看怎么建立数据表的命令用第二种方法最佳。   
0 0
原创粉丝点击