简体   繁体   English

如何知道列是否在mysql中自动递增

[英]how to know if a column is auto-increment in mysql

I want to generate insert sql statement according to the tables in database, so write some code to do this, the DataProvider is MySQL Connector/Net. 我想根据数据库中的表生成insert sql语句,所以写一些代码来做到这一点,DataProvider是MySQL Connector / Net。

MysqlConnection conn = new MysqlConnection("...");
DataTable dt = conn.GetSchema("Tables");

//foreach table

DataTable dt = conn.GetSchema("Columns",column_res);

//generate prepared statement sql by the columns.

When there is auto_increment column in table, the code can't work and I must edit it manually. 当表中有auto_increment列时,代码将无法工作,我必须手动对其进行编辑。 Does anyone has any idea about how to know a column is auto_increment? 有谁知道如何知道列为auto_increment吗? So I can get all the sql needed automatically. 这样我就可以自动获取所有需要的sql。

For the MySql Connector/Net,there is a "EXTRA" column in the dt of the step. 对于MySql Connector / Net,在步骤dt中有一个“ EXTRA”列。

DataTable dt = conn.GetSchema("Columns",column_res);

if the column is auto_increment, the value of dt.Rows[i]["EXTRA"] is "auto increment". 如果该列是auto_increment,则dt.Rows [i] [“ EXTRA”]的值是“自动增量”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .NET 5 - 防止更新自动增量列? - .NET 5 - Prevent update on auto-increment column? 动态绑定的DataGridView在自动增量列上显示-1值吗? - Dynamically bound DataGridView shows -1 value on auto-increment column? 使用自动递增ID向数据库添加值 - Adding values to database with an auto-increment Id 自动增量int列BUT还允许手动输入吗? 不能使用主键 - Auto-increment int column BUT also allow manual input? Can't use primary key 如何让 EFCore 内存数据库自动递增非关键字段 - How to get EFCore In-memory db to auto-increment non-key fields SqLite自动递增其组合键之一 - SqLite Auto-increment for one its Composite Keys 从表中删除内容后,如何在 C# 的内置 SQL 数据库中将自动增量重置为从 1 开始? - How do I reset Auto-Increment to start from 1 in built-in SQL Database of C# after deleting contents from table? 自动递增列.NET - Auto increment column .NET 如何更新ID和自动递增列所涉及的特定行 - How to update a specific row where ID, and an auto increment column are involve 在 EF Core + SQLite 中使用自动增量/ValueGeneratedOnAdd 时,“值不能为空” - "Value cannot be null" when using auto-increment/ValueGeneratedOnAdd with EF Core + SQLite
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM