资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

怎么看mysql建表语句 查询mysql建表语句

如何查看 mysql 建库 建表语句

打开mySQL

10年积累的网站制作、成都网站制作经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先网站策划后付款的网站建设流程,更有怀安免费网站建设让你可以放心的选择与我们合作。

敲入代码:show databases; 【按回车】 // 显示所有库;

新建库:create database db_stu ; 【按回车】

使用库:use db_stu ; 【按回车】

在新建的db_stu库中建表:

create table tbl_stu(

int age,

float score,

int name,

int mark); 【按回车】

3

查询表内容:

desc tbl_stu; 【按回车】

Mysql怎样查看某个表的建表语句导出建表sql语句

假设表名为MyTable的话,

建表语句:

mysql show create table MyTable;

查看表字段定义:

方式1、

mysql desc MyTable;

方式2、

mysql use information_schema;

mysql select * from columns where table_name='MyTable';

在mysql里查看表,把表打出来的语句

TABLE 语句

具体语法:TABLE table_name [ORDER BY column_name] [LIMIT number [OFFSET number]]

其实从语法上看,可以排序,也可以过滤记录集,不过比较简单,没有 SELECT 那么强大。

示例 1

简单的建一张很小的表 y1,记录数为 10 条。表 t1,插入 10 条记录

mysql-(ytt/3305)-create table t1 (r1 int,r2 int);

Query OK, 0 rows affected (0.02 sec)

mysql-(ytt/3305)-insert into t1

with recursive aa(a,b) as (

select 1,1

union all

select a+1,ceil(rand()*20) from aa where a 10

) select * from aa;

Query OK, 10 rows affected (0.00 sec)

Records: 10  Duplicates: 0  Warnings: 0

简单全表扫描mysql-(ytt/3305)-select * from t1;+------+------+| r1   | r2   |+------+------+|    1 |    1 ||    2 |    9 ||    3 |    9 ||    4 |   17 ||    5 |   17 ||    6 |   16 ||    7 |    6 ||    8 |    1 ||    9 |   10 ||   10 |    3 |+------+------+10 rows in set (0.00 sec)

TABLE 结果mysql-(ytt/3305)-table t1;+------+------+| r1   | r2   |+------+------+|    1 |    1 ||    2 |    9 ||    3 |    9 ||    4 |   17 ||    5 |   17 ||    6 |   16 ||    7 |    6 ||    8 |    1 ||    9 |   10 ||   10 |    3 |+------+------+10 rows in set (0.00 sec)

看下 table 的执行计划mysql-(ytt/3305)-explain table t1 order by r1 limit 2\G*************************** 1. row ***************************           id: 1  select_type: SIMPLE        table: t1   partitions: NULL         type: ALLpossible_keys: NULL          key: NULL      key_len: NULL          ref: NULL         rows: 10     filtered: 100.00        Extra: Using filesort1 row in set, 1 warning (0.00 sec)

其实可以看到 TABLE 内部被 MySQL 转换为 SELECT 了。mysql-(ytt/3305)-show warnings\G*************************** 1. row ***************************  Level: Note   Code: 1003Message: /* select#1 */ select `ytt`.`t1`.`r1` AS `r1`,`ytt`.`t1`.`r2` AS `r2` from `ytt`.`t1` order by `ytt`.`t1`.`r1` limit 21 row in set (0.00 sec)

那其实从上面简单的例子可以看到 TABLE 在内部被转成了普通的 SELECT 来处理。示例 2应用于子查询里的子表。这里要注意,内表的字段数量必须和外表过滤的字段数量一致。克隆表 t1 结构mysql-(ytt/3305)-create table t2 like t1;Query OK, 0 rows affected (0.02 sec)

克隆表 t1 数据mysql-(ytt/3305)-insert into t2 table t1;Query OK, 10 rows affected (0.00 sec)Records: 10  Duplicates: 0  Warnings: 0

table t1 被当做内表,表 t1 有两个字段,必须同时满足 t2 检索时过滤的字段也是两个。mysql-(ytt/3305)-select * from t2 where (r1,r2) in (table t1);+------+------+| r1   | r2   |+------+------+|    1 |    1 ||    2 |    9 ||    3 |    9 ||    4 |   17 ||    5 |   17 ||    6 |   16 ||    7 |    6 ||    8 |    1 ||    9 |   10 ||   10 |    3 |+------+------+10 rows in set (0.00 sec)

注意:这里如果过滤的字段数量和子表数量不一致,则会报错。

mysql数据库如何查看创建表的代码

采用命令show create table table_name即可查看MySQL数据库表的建表语句。


名称栏目:怎么看mysql建表语句 查询mysql建表语句
网站路径:http://cdkjz.cn/article/dodcdpj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220