要在MySQL中查找列是否为auto_increment,您可以使用以下语法 −
select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yourDatabaseName' and TABLE_NAME='yourTableName' and EXTRA like '%auto_increment%';
Let us first create a table. Here, ClientId is set AUTO_INCREMENT −
mysql> create table autoIncrementTableDemo -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int, -> ClientAddress varchar(100), -> ClientCountryName varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)
现在,让我们找出是否有任何列是auto_increment −
mysql> select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='test' and TABLE_NAME='autoIncrementTableDemo' and EXTRA like '%auto_increment%';
以下是输出结果,显示了列,即auto_increment −
+-------------+ | COLUMN_NAME | +-------------+ | ClientId | +-------------+ 1 row in set (0.00 sec)
以上是如何在MySQL中找到一个列是否为自增列?的详细内容。更多信息请关注PHP中文网其他相关文章!