How to generate a create table script for an existing table in phpmyadmin?

前端 未结 11 2120
旧时难觅i
旧时难觅i 2020-12-02 03:59

How can I generate a create table script for an existing table in phpmyadmin?

相关标签:
11条回答
  • 2020-12-02 04:31

    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.

    0 讨论(0)
  • 2020-12-02 04:32

    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.

    0 讨论(0)
  • 2020-12-02 04:32

    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.

    0 讨论(0)
  • 2020-12-02 04:34

    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
    
    0 讨论(0)
  • 2020-12-02 04:36

    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);
    }
    
    0 讨论(0)
提交回复
热议问题