[英]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.