如何在phpmyadmin中为现有的表生成创建表脚本?
当前回答
执行SHOW CREATE TABLE <表名>;查询
其他回答
右击表名 选择开放式餐桌 进入信息选项卡
向下滚动查看创建表脚本
这可能是一个晚答复。但它可能会帮助其他人。在MY SQL Workbench中非常简单(我使用的是Workbench版本6.3和MY SQL版本5.1社区版):右键单击需要创建脚本的表,选择“复制到剪贴板—>创建语句”选项。只需粘贴任何文本编辑器,您想要获得创建脚本。
导出整个数据库选择格式为SQL。现在,使用notepad, notepad++或任何编辑器打开你下载的SQL文件。您将看到数据库的所有表和插入查询。所有脚本都将在那里可用。
使用PHP函数。
当然查询函数($this->模型)你必须改变自己。
/**
* Creating a copy table based on the current one
*
* @param type $table_to_copy
* @param type $new_table_name
* @return type
* @throws Exception
*/
public function create($table_to_copy, $new_table_name)
{
$sql = "SHOW CREATE TABLE ".$table_to_copy;
$res = $this->model->queryRow($sql, PDO::FETCH_ASSOC);
if(!filled($res['Create Table']))
throw new Exception('Could not get the create code for '.$table_to_copy);
$newCreateSql = preg_replace(array(
'@CREATE TABLE `'.$table_to_copy.'`@',
'@KEY `'.$table_to_copy.'(.*?)`@',
'@CONSTRAINT `'.$table_to_copy.'(.*?)`@',
'@AUTO_INCREMENT=(.*?) @',
), array(
'CREATE TABLE `'.$new_table_name.'`',
'KEY `'.$new_table_name.'$1`',
'CONSTRAINT `'.$new_table_name.'$1`',
'AUTO_INCREMENT=1 ',
), $res['Create Table']);
return $this->model->exec($newCreateSql);
}
可以查询“information_schema”。直接列:
SELECT * FROM information_schema.columns
WHERE table_name = 'your_table' AND table_schema = 'your_database'