要在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中文網其他相關文章!