如何检测MySQL数据库结构是否已更改(不是内容)?
我们首先来看一个示例并创建一个表-
create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(40), StudentAge int, StudentMarks int );
以下是查询以了解数据库结构-
show create table DemoTable;
这将产生以下输出-
+---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DemoTable | CREATE TABLE `DemoTable` (`StudentId` int(11) NOT NULL AUTO_INCREMENT, `StudentName` archar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `StudentAge` int(11) DEFAULT NULL, `StudentMarks` int(11) DEFAULT NULL, PRIMARY KEY (`StudentId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci | +---------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.06 sec)
现在,让我们更改数据库结构-
alter table DemoTable add column StudentCountryName varchar(20); Records : 0 Duplicates : 0 Warnings : 0
现在,我们将再次检查数据库结构-
show create table DemoTable;
这将产生以下输出。我们现在可以匹配结构中的更改-
+---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | DemoTable | CREATE TABLE `DemoTable` ( `StudentId` int(11) NOT NULL AUTO_INCREMENT, `StudentName` varchar(40) COLLATE utf8_unicode_ci DEFAULT NULL, `StudentAge` int(11) DEFAULT NULL, `StudentMarks` int(11) DEFAULT NULL, `StudentCountryName` varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL, PRIMARY KEY (`StudentId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci | +---------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短