How can I generate a create table script for an existing table in phpmyadmin?
Export whole database select format as SQL. Now, open that SQL file which you have downloaded using notepad, notepad++ or any editor. You will see all the tables and insert queries of your database. All scripts will be available there.
Run query is sql tab
SHOW CREATE TABLE tableName
Click on
+Options -> Choose Full texts -> Click on Go
Copy Create Table query and paste where you want to create new table.
This may be a late reply. But it may help others. It is very simple in MY SQL Workbench ( I am using Workbench version 6.3 and My SQL Version 5.1 Community edition): Right click on the table for which you want the create script, select 'Copy to Clipboard --> Create Statement' option. Simply paste in any text editor you want to get the create script.
I found another way to export table in sql file.
Suppose my table is abs_item_variations
abs_item_variations ->structure -> propose table structure -> export -> Go
Using PHP Function.
Of course query function ($this->model) you have to change to your own.
/**
* 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);
}