MySQL Desc指令相关  

2011-08-09 11:25:50|  分类: my基本命令 |举报 |字号 订阅

1、desc tablename;
例如 :mysql> desc jos_modules;
+------------------+---------------------+------+-----+---------------------+----------------+
| Field              | Type 
              | Null   |
  Key   | Default            
| Extra          |
+--------------- ---+---------------------+------+-----+---------------------+----------------+
| id                   | int(11)
            | NO    | PRI    
 | NULL                |
auto_increment |
| title                | text  
               | NO    |
           | NULL       
        |            
              |
| content          | text      
           | NO    |    
       | NULL          
     |                
          |
| ordering         | int(11)    
        | NO    |      
     | 0                
     |                
          |
+------------------+---------------------+------+-----+---------------------+----------------+

使用MySQL数据库desc 表名时,我们看到Key那一栏,可能会有4种值,即' ','PRI','UNI','MUL'。
1. 如果Key是空的, 那么该列值的可以重复, 表示该列没有索引, 或者是一个非唯一的复合索引的非前导列;
2. 如果Key是PRI,  那么该列是主键的组成部分;
3. 如果Key是UNI,  那么该列是一个唯一值索引的第一列(前导列),并别不能含有空值(NULL);
4. 如果Key是MUL,  那么该列的值可以重复, 该列是一个非唯一索引的前导列(第一列)或者是一个唯一性索引的组成部分但是可以含有空值NULL。
如果对于一个列的定义,同时满足上述4种情况的多种,比如一个列既是PRI,又是UNI,那么"desc 表名"的时候,显示的Key值按照优先级来显示 PRI->UNI->MUL。那么此时,显示PRI。
一个唯一性索引列可以显示为PRI,并且该列不能含有空值,同时该表没有主键。
一个唯一性索引列可以显示为MUL, 如果多列构成了一个唯一性复合索引,因为虽然索引的多列组合是唯一的,比如ID+NAME是唯一的,但是没一个单独的列依然可以有重复的值,只要ID+NAME是唯一的即可。

查看mysql表结构的方法有三种:
1、desc tablename;
例如:
要查看jos_modules表结构的命令:
desc jos_modules;
查看结果:
mysql> desc jos_modules;
+------------------+---------------------+------+-----+---------------------+----------------+
| Field            |
Type               
| Null | Key |
Default            
| Extra          |
+------------------+---------------------+------+-----+---------------------+----------------+
|
id              
| int(11)            
| NO   | PRI |
NULL               
| auto_increment |
| title            |
text               
| NO   |     | NULL               
|               
|
| content          |
text               
| NO   |     |
NULL               
|               
|
| ordering         |
int(11)            
| NO   |     |
0                  
|               
|
| position         |
varchar(50)         | YES
|     |
NULL               
|               
|
| checked_out      | int(11)
unsigned    | NO   |     |
0                  
|               
|
| checked_out_time |
datetime            |
NO   |     | 0000-00-00 00:00:00
|               
|
| published        |
tinyint(1)          |
NO   | MUL |
0                  
|               
|
| module           |
varchar(50)         | YES | MUL |
NULL               
|               
|
| numnews          |
int(11)            
| NO   |     |
0                  
|               
|
| access           |
tinyint(3) unsigned | NO   |     |
0                  
|               
|
| showtitle        | tinyint(3) unsigned |
NO   |     |
1                  
|               
|
| params           |
text               
| NO   |     |
NULL               
|               
|
| iscore           |
tinyint(4)          |
NO   |     |
0                  
|               
|
| client_id        |
tinyint(4)          |
NO   |     |
0                  
|               
|
| control          |
text               
| NO   |     |
NULL               
|               
|
+------------------+---------------------+------+-----+---------------------+----------------+
2、show create table tablename;
例如:
要查看jos_modules表结构的命令:
show create table jos_modules;
查看结果:
mysql> show create table jos_modules;
jos_modules | CREATE TABLE `jos_modules` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` text NOT NULL,
`content` text NOT NULL,
`ordering` int(11) NOT NULL DEFAULT '0',
`position` varchar(50) DEFAULT NULL,
`checked_out` int(11) unsigned NOT NULL DEFAULT '0',
`checked_out_time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`published` tinyint(1) NOT NULL DEFAULT '0',
`module` varchar(50) DEFAULT NULL,
`numnews` int(11) NOT NULL DEFAULT '0',
`access` tinyint(3) unsigned NOT NULL DEFAULT '0',
`showtitle` tinyint(3) unsigned NOT NULL DEFAULT '1',
`params` text NOT NULL,
`iscore` tinyint(4) NOT NULL DEFAULT '0',
`client_id` tinyint(4) NOT NULL DEFAULT '0',
`control` text NOT NULL,
PRIMARY KEY (`id`),
KEY `published` (`published`,`access`),
KEY `newsfeeds` (`module`,`published`)
) ENGINE=MyISAM AUTO_INCREMENT=145 DEFAULT CHARSET=utf8 
3、use information_schema;select * from columns where
table_name='tablename'
例如:
要查看jos_modules表结构的命令:
use information_schema;
select * from columns where table_name='jos_modules';
查看结果:
略。
如果要查看怎么建立数据表的命令用第二种方法最佳

MySQL Desc指令相关的更多相关文章

  1. MySQL常用指令,java,php程序员,数据库工程师必备。程序员小冰常用资料整理

    MySQL常用指令,java,php程序员,数据库工程师必备.程序员小冰常用资料整理 MySQL常用指令(备查) 最常用的显示命令: 1.显示数据库列表. show databases; 2.显示库中 ...

  2. mysql数据库内容相关操作

    第一:介绍 mysql数据内容的操作主要是: INSERT实现数据的插入 UPDATE实现数据的更新 DLETE实现数据的删除 SELECT实现数据的查询. 第二:增(insert) 1.插入完整的数 ...

  3. Mysql查看连接数相关信息

    MySQL查看连接数相关信息在 数据库:INFORMATION_SCHEMA 表:PROCESSLIST 表结构如下: mysql> desc PROCESSLIST; +---------+- ...

  4. MySQL的日志相关内容

    本篇文章介绍一下mysql的备份和日志,由于备份时需要用到日志,所以在讲备份前,如果日志内容篇幅过长,将会把日志和备份分开单独来讲,先简单介绍一下mysql的日志相关内容. MySQL日志 日志是my ...

  5. Ubuntu Mysql 常用指令

    mysql 常用指令及中文乱码解决 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...

  6. 【风马一族_mysql】mysql基本指令

    船停在港湾是很安全的,但那不是造船的目的! 用户 创建用户 mysql>grant 权限(select,insert,update,delete) on  数据库.数据表  to  用户名@电脑 ...

  7. python操作mysql数据库的相关操作实例

    python操作mysql数据库的相关操作实例 # -*- coding: utf-8 -*- #python operate mysql database import MySQLdb #数据库名称 ...

  8. MySql性能优化相关

    原来使用MySql处理的数据量比较少,小打小闹的,没有关注过性能的问题.最近要处理的数据量飙升,每天至少20W行的新增数据,导致MySql在性能方面已经是差到不可用的地步了,必须要重视MySql的优化 ...

  9. PHP对MySQL数据库的相关操作

    一.Apache服务器的安装 <1>安装版(计算机相关专业所用软件---百度云链接下载)-直接install<2>非安装版(https://www.apachehaus.com ...

随机推荐

  1. MVC使用AdditionalMetadata为Model属性添加额外信息

    当需要为Model的属性添加一些额外信息的时候,使用[AdditionalMetadata("somekey", "some content")]是不错的选择, ...

  2. [翻译] FreeStreamer 在线流媒体播放

    FreeStreamer https://github.com/muhku/FreeStreamer Introduction FreeStreamer is an audio player engi ...

  3. MySQL Workbench update语句错误Error Code: 1175.

    rom:http://www.tuicool.com/articles/NJ3QRz MySQL update error: Error Code: 1175. You are using safe ...

  4. 解决Sqoop报错Could not load db driver class: com.intersys.jdbc.CacheDriver

    报错栈: // :: INFO tool.CodeGenTool: Beginning code generation // :: ERROR sqoop.Sqoop: Got exception r ...

  5. Coursera课程《大家的Python》中一些资料

    Printed copies of Python for Informatics are available for $10 or less from Amazon and $2 or less on ...

  6. 在Xcode中显示代码行号

    打开一个程序,点击屏幕菜单栏的Xcode,然后选Xcode -> Preferences -> Text Editing -> Show line numbers前面打勾就行了. 如 ...

  7. poj 1007 Quoit Design(分治)

    Quoit Design Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  8. flume 日志导入elasticsearch

    Flume配置 . flume生成的数据结构 <span style="font-size:18px;">"_index" : "logs ...

  9. DDR SDRAM芯片DQS的作用以及读写DQS/DQ对齐方式不同的原因

    节选内容转载自https://www.design-reuse.com/articles/13805/the-love-hate-relationship-with-ddr-sdram-control ...

  10. [Linux]在终端启动程序关闭终端不退出的方法

    一般情况下关闭终端时,那么在这个终端中启动的后台程序也会终止,要使终端关闭后,后台程序保持执行,使用这个指令: nohup 命令 & 如:nohup test.sh & 回车,然后提示 ...