DESC table_name;
DESC table_name;をすることで、該当テーブルの各カラムの情報一覧が表示されます。
※show columns from table_name;でも同じ結果出ます。
mysql> desc shops;
+-------------+-----------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------+------+-----+---------+----------------+
| id | bigint unsigned | NO | PRI | NULL | auto_increment |
| ownerId | bigint unsigned | NO | MUL | NULL | |
| name | varchar(255) | NO | | NULL | |
| information | text | NO | | NULL | |
| imageName | varchar(255) | NO | | NULL | |
| isEnable | tinyint(1) | NO | | NULL | |
| created_at | timestamp | YES | | NULL | |
| updated_at | timestamp | YES | | NULL | |
+-------------+-----------------+------+-----+---------+----------------+
8 rows in set (0.02 sec)
SHOW CREATE TABLE table_name;
外部キー設定やカスケード設定など、より詳細な確認をするにはSHOW CREATE TABLE table_name;をすることで確認できます。
| shops | CREATE TABLE `shops` (
`id` bigint unsigned NOT NULL AUTO_INCREMENT,
`ownerId` bigint unsigned NOT NULL,
`name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`information` text COLLATE utf8mb4_unicode_ci NOT NULL,
`imageName` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
`isEnable` tinyint(1) NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `shops_ownerid_foreign` (`ownerId`),
CONSTRAINT `shops_ownerid_foreign` FOREIGN KEY (`ownerId`) REFERENCES `owners` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
コメント