自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

mysql快速建表的方法

數(shù)據(jù)庫(kù) MySQL
建表是mysql數(shù)據(jù)庫(kù)的基礎(chǔ)知識(shí),下文就為您介紹了兩種常用的快速建表的方法,如果您對(duì)此方面感興趣的話,不妨一看。

mysql快速建表的語(yǔ)句寫(xiě)法并不復(fù)雜,下面就為您詳細(xì)介紹兩種最常用的mysql快速建表的語(yǔ)句:

  1. 1:create table t_select select * from t_old where 1 = 0;  
  2. 2:create table t_select1 like t_old;  

但是***種mysql快速建表的語(yǔ)句有缺陷,他能取消原來(lái)表的有些定義。(手冊(cè)上說(shuō)Some conversion of data types might occur. For example, the AUTO_INCREMENT attribute is not preserved, and VARCHAR columns can become CHAR columns. )
可以看看下面的例子

  1. create table t_old (id serial, content varchar(8000) not null,`desc` varchar(100) not null) engine innodb;  
  2. show CREATE table t_old;  
  3. | Table | Create Table                                                                        
  4.  
  5.  | t_old | CREATE TABLE `t_old` (  
  6. `id` bigint(20) unsigned NOT NULL auto_increment,  
  7. `content` varchar(8000) NOT NULL,  
  8. `desc` varchar(100) NOT NULL,  
  9. UNIQUE KEY `id` (`id`)  
  10. ENGINE=InnoDB DEFAULT CHARSET=utf8 
  11.  
  12. create table t_select select * from t_old where 1 = 0;   
  13. CREATE TABLE `t_select` (  
  14. `id` bigint(20) unsigned NOT NULL default '0',  
  15. `content` varchar(8000) NOT NULL,  
  16. `desc` varchar(100) NOT NULL  
  17. ENGINE=MyISAM DEFAULT CHARSET=utf8   
  18.  

這樣 自增字段跟表引擎都變了
如果想要保持一樣的引擎,就加上:engine innodb
如:

  1. create table t_select engine innodb select * from t_old where 1 = 0; create table t_like like t_old;  
  2. show CREATE table t_like;  
  3. Table                                                    | t_like | CREATE TABLE `t_like` (  
  4. `id` bigint(20) unsigned NOT NULL auto_increment,  
  5. `content` varchar(8000) NOT NULL,  
  6. `desc` varchar(100) NOT NULL,  
  7. UNIQUE KEY `id` (`id`)  
  8. ENGINE=InnoDB DEFAULT CHARSET=utf8   
  9.  

這樣引擎跟自增字段都沒(méi)有變

看下面一個(gè)一個(gè)例子,就知道有什么變化了

  1. CREATE TABLE `t4_innodb` (                 
  2. `id` int(11) NOT NULL AUTO_INCREMENT,    
  3. `a1` int(11) NOT NULL,                   
  4. `a2` int(11) DEFAULT NULL,               
  5. `remark` varchar(200) NOT NULL,          
  6. PRIMARY KEY (`id`),                      
  7. KEY `a1_2_idx` (`a1`)                    
  8. ENGINE=InnoDB DEFAULT CHARSET=utf8     
  9.  
  10. create table t6_innodb select * from t4_innodb where 1=2;  
  11. CREATE TABLE `t6_innodb` (              
  12. `id` int(11) NOT NULL DEFAULT '0',    
  13. `a1` int(11) NOT NULL,                
  14. `a2` int(11) DEFAULT NULL,            
  15. `remark` varchar(200) NOT NULL        
  16. ENGINE=InnoDB DEFAULT CHARSET=utf8   
  17.  
  18. create table t8_innodb like t4_innodb;  
  19.  
  20. CREATE TABLE `t8_innodb` (                 
  21. `id` int(11) NOT NULL AUTO_INCREMENT,    
  22. `a1` int(11) NOT NULL,                   
  23. `a2` int(11) DEFAULT NULL,               
  24. `remark` varchar(200) NOT NULL,          
  25. PRIMARY KEY (`id`),                      
  26. KEY `a1_2_idx` (`a1`)                    
  27. ENGINE=InnoDB DEFAULT CHARSET=utf8    
  28.  

 

 

 

【編輯推薦】

MySQL大表備份的簡(jiǎn)單方法

MySQL中文建表問(wèn)題解析

MySQL添加字段和修改字段的方法

MySQL授權(quán)表使用示例

MySQL內(nèi)存表的弊端

責(zé)任編輯:段燃 來(lái)源: 互聯(lián)網(wǎng)
相關(guān)推薦

2010-10-15 10:14:09

Mysql建表

2010-11-23 10:11:23

mysql建表亂碼

2010-09-16 09:49:38

sql server建

2010-11-23 15:50:44

MySQL中文建表

2011-02-25 14:52:10

Proftpd建表

2010-10-11 17:23:47

mysql建主從服務(wù)器

2010-11-23 09:57:36

MYSQL表信息

2010-10-15 10:37:27

MySQL創(chuàng)建關(guān)聯(lián)表

2010-10-15 10:58:13

Mysql清空表

2021-03-02 11:07:54

MySQL建表引導(dǎo)

2010-11-25 16:29:26

MySQL慢日志查詢(xún)

2010-11-23 15:33:17

MySQL分表處理

2010-11-23 09:13:47

mysql修改表結(jié)構(gòu)

2010-10-15 11:05:31

MYSQL查詢(xún)結(jié)果

2010-10-14 14:43:45

MySQL聯(lián)表查詢(xún)

2010-09-30 11:44:40

DB2表快速清空

2010-06-10 14:14:18

個(gè)MySQL表索引

2010-11-24 13:11:06

MySQL遍歷數(shù)據(jù)表

2010-11-23 16:21:07

MySQL大表備份

2010-11-24 14:36:25

修復(fù)mysql表
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)