mysql查看錶結構和表建立語命令,mysql查看錶結構

來源:互聯網
上載者:User

mysql查看錶結構和表建立語命令,mysql查看錶結構

1,desc tablename;

mysql> desc authors;+-------+--------------+------+-----+---------+----------------+| Field | Type         | Null | Key | Default | Extra          |+-------+--------------+------+-----+---------+----------------+| id    | int(11)      | NO   | PRI | NULL    | auto_increment || email | varchar(100) | NO   | UNI | NULL    |                || name  | varchar(100) | NO   |     | NULL    |                |+-------+--------------+------+-----+---------+----------------+3 rows in set

2,show create table tablename; 

mysql> show create table authors;+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| Table   | Create Table                                                                                                                                                                                                                           |+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+| authors | CREATE TABLE `authors` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `email` varchar(100) NOT NULL,  `name` varchar(100) NOT NULL,  PRIMARY KEY (`id`),  UNIQUE KEY `email` (`email`)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 |+---------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+1 row in set

3,select * from columns where table_name='表名'


mysql> use information_schema;
Database changed
mysql> select * from columns where table_name='authors';  
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+-----------------+--------------+------------+----------------+---------------------------------+----------------+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | CHARACTER_SET_NAME | COLLATION_NAME  | COLUMN_TYPE  | COLUMN_KEY | EXTRA          | PRIVILEGES                      | COLUMN_COMMENT |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+-----------------+--------------+------------+----------------+---------------------------------+----------------+
| def           | zqad         | authors    | id          |                1 | NULL           | NO          | int       | NULL                     | NULL                   |                10 |             0 | NULL               | NULL            | int(11)      | PRI        | auto_increment | select,insert,update,references |                |
| def           | zqad         | authors    | email       |                2 | NULL           | NO          | varchar   |                      100 |                    300 | NULL              | NULL          | utf8               | utf8_general_ci | varchar(100) | UNI        |                | select,insert,update,references |                |
| def           | zqad         | authors    | name        |                3 | NULL           | NO          | varchar   |                      100 |                    300 | NULL              | NULL          | utf8               | utf8_general_ci | varchar(100) |            |                | select,insert,update,references |                |
+---------------+--------------+------------+-------------+------------------+----------------+-------------+-----------+--------------------------+------------------------+-------------------+---------------+--------------------+-----------------+--------------+------------+----------------+---------------------------------+----------------+
3 rows in set


mysql建表語句怎寫,表結構是什樣的

create table 表名
(
id int(11) not null auto_increment, //看是否要設定為自增長
欄位名 varchar(50) null,
欄位名 date null,
欄位名 varchar(50) null,
欄位名 varchar(50) null,
欄位名 float(13,0) null,
欄位名 int null,
primary key(id) //設定ID為主鍵
)ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=gbk AUTO_INCREMENT=5 ;

charset=gbk //這個是指你的資料庫字元集是什麼,這裡是GBK
如果是utf8 charset=utf8
 
oracle 怎擷取表的結構,就像mysql裡的desc命令一樣的功可以,

查看錶結構的:desc (表名);建立表的create語句就是在plsql上按住Ctrl鍵點擊該表名然後在點擊這個頁面右下角的“查看sql“按鈕就可以看到了 ;不使用工具的話,先把表匯出來然後在導進去,導進去的時候使用show=y、log這兩個選項,就可以查看了!
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.