How can I generate a create table script for an existing table in phpmyadmin?
How can I generate a create table script for an existing table in phpmyadmin?
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.
Use the following query in sql tab:
SHOW CREATE TABLE your_table_name
Press GO button
After show table, above the table ( +options ) Hyperlink.
Press +options Hyperlink then appear some options select (Full texts) press GO button.
Show sql quaery.
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);
}
Right click on table name-->choose open table --> Go to Info Tab
and the scroll down to see create table script
After show table, above the table ( +options ) Hyperlink is there.
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
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.
In MySQL workbench, you get the already created table script, by just right click on the specific table, then select send to SQL editor>>create statement. That's all you will get the create table script on the editor.