Mariadb

包含 CREATE TABLE 中所有屬性的 PMA 導出

  • July 25, 2020

這是導出的預設 PMA 輸出:

CREATE TABLE `foo` (
 `id` int(11) UNSIGNED NOT NULL,
 `fk_id` int(11) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `foo`
 ADD PRIMARY KEY (`id`);

ALTER TABLE `foo`
 MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `foo`
 ADD CONSTRAINT `foo_ibfk_1` FOREIGN KEY (`fk_id`) REFERENCES `bar` (`id`),

...

有沒有辦法獲得將以下所有內容ALTER TABLE合併語句CREATE TABLE中的導出?

我顯示了您所做的所有更改,如您在範例中所見

架構 (MySQL v8.0)

CREATE TABLE `bar` (`id` int(11) UNSIGNED,PRIMARY KEY (`id`));
CREATE TABLE `foo` (
 `id` int(11) UNSIGNED NOT NULL,
 `fk_id` int(11) UNSIGNED NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `foo`
 ADD PRIMARY KEY (`id`);

ALTER TABLE `foo`
 MODIFY `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT;

ALTER TABLE `foo`
 ADD CONSTRAINT `foo_ibfk_1` FOREIGN KEY (`fk_id`) REFERENCES `bar` (`id`);

查詢 #1

SHOW CREATE  TABLE foo;

| Table | Create Table                                                                                                                                                                                                                                                                                              |
| ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| foo   | CREATE TABLE `foo` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `fk_id` int(11) unsigned NOT NULL,
 PRIMARY KEY (`id`),
 KEY `foo_ibfk_1` (`fk_id`),
 CONSTRAINT `foo_ibfk_1` FOREIGN KEY (`fk_id`) REFERENCES `bar` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci |

在 DB Fiddle 上查看

引用自:https://dba.stackexchange.com/questions/271633