日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

mysql create table 语法详解

發(fā)布時間:2025/3/15 数据库 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql create table 语法详解 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

create table 可以分成三類

?

一、一般create table 語句

  1  語法

create [temporary] table [if not exists] tbl_name(create_definition)[table_options][parttion_options]

  2  例子:創(chuàng)建一個person表它包涵id,name,birthday這幾個列

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  例子:定義一個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_expression

  2  例子:

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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。