mysql create table 语法详解
生活随笔
收集整理的這篇文章主要介紹了
mysql create table 语法详解
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
create table 可以分成三類
?
一、一般create table 語句:
1 語法
create [temporary] table [if not exists] tbl_name(create_definition)[table_options][parttion_options]2 例子:創(chuàng)建一個(gè)person表它包涵id,name,birthday這幾個(gè)列
create table person(id int not null auto_increment,name varchar(8),birthday datetime,constraint pk__person primary key(id));?
二、create table like 參照已有表的定義,來定義新的表:
1 語法
create [temporary] table [if not exists] tbl_name {like old_tbl_name | (like old_tbl_name)};2 例子:定義一個(gè)person_like 表,它的表結(jié)構(gòu)參照上面例子中的person表
mysql> create table person_like like person; Query OK, 0 rows affected (0.01 sec)mysql> show create table person_like \G *************************** 1. row ***************************Table: person_like Create Table: CREATE TABLE `person_like` (`id` int(11) NOT NULL AUTO_INCREMENT,`name` varchar(8) DEFAULT NULL,`birthday` datetime DEFAULT NULL,PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)可以看出使用create table like 方式創(chuàng)建的表,它的表結(jié)構(gòu)和原表是一樣的。
?
三、根據(jù)select 的結(jié)果集來創(chuàng)建表:
1 語法
create [temporary] table [if not exists] tbl_name[(create_definition,...)][table_options][partition_options][ignore | replace][as] query_expression2 例子:
mysql> create table person_as -> as -> select id,name from person; Query OK, 0 rows affected (0.01 sec) Records: 0 Duplicates: 0 Warnings: 0mysql> show create table person_as \G *************************** 1. row ***************************Table: person_as Create Table: CREATE TABLE `person_as` (`id` int(11) NOT NULL DEFAULT '0',`name` varchar(8) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 1 row in set (0.00 sec)?
?
?
?
?
?
----
轉(zhuǎn)載于:https://www.cnblogs.com/JiangLe/p/7009205.html
總結(jié)
以上是生活随笔為你收集整理的mysql create table 语法详解的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux 进程地址空间 进程内存布局
- 下一篇: IPv4和IPv6有什么异同?