If you need to copy the structure without data from one table to another does not necessarily make a dump of the structure and the changes it name and importing already modified dump the database. Developers MySQL all have come up for us:)

In order to create a new table that is based on the existing copy the structure of one table to another, perform command :

CREATE & lt; new_table & gt; LIKE & lt; original_table & gt;

Consider an example.
We have a table of known base TECDOC. It has the structure:

CREATE TABLE `ARTICLES` (
  `ART_ID` int (11) NOT NULL,
  `ART_ARTICLE_NR` varchar (66) NOT NULL,
  `ART_SUP_ID` ​​smallint (6) DEFAULT NULL,
  `ART_DES_ID` int (11) DEFAULT NULL,
  `ART_COMPLETE_DES_ID` int (11) DEFAULT NULL,
  `ART_PACK_SELFSERVICE` smallint (6) DEFAULT NULL,
  `ART_MATERIAL_MARK` smallint (6) DEFAULT NULL,
  `ART_REPLACEMENT` smallint (6) DEFAULT NULL,
  `ART_ACCESSORY` smallint (6) DEFAULT NULL,
  `ART_BATCH_SIZE1` int (11) DEFAULT NULL,
  `ART_BATCH_SIZE2` int (11) DEFAULT NULL,
  `Art_url` varchar (255) NOT NULL DEFAULT ”,
  `Art_url2` varchar (255) NOT NULL DEFAULT ”,
  PRIMARY KEY (`ART_ID`),
  KEY `ART_SUP_ID` ​​(` ART_SUP_ID`),
  KEY `ART_DES_ID` (` ART_DES_ID`),
  KEY `ART_COMPLETE_DES_ID` (` ART_COMPLETE_DES_ID`),
  KEY `ART_ARTICLE_NR` (` ART_ARTICLE_NR` (18))
) ENGINE = MyISAM DEFAULT CHARSET = utf8;

For the tests we need to copy the structure of the table in the table `ARTICLES_TEST`.
Execute the command:

CREATE ARTICLES LIKE ARTICLES_TEST

MySQL Server will create an identical table structure with indexes, but without the data.

(Visited 353 times, 1 visits today)
adminTips
If you need to copy the structure without data from one table to another does not necessarily make a dump of the structure and the changes it name and importing already modified dump the database. Developers MySQL all have come up for us:) In order to create...

Do you want to be notified about new DBA updates, releases, jobs and free tips? Join our email newsletter. It's fast and easy. You will be among the first to know about hot new DBA updates and stuff, it will help you enhance your DBA skills.
We take your privacy very seriously