执行插入查询时如何增加行ID 1 [英] How Do I Increment Rows Id By1 When Insert Query Is Executed..
本文介绍了执行插入查询时如何增加行ID 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
SqlCommand cmd = new SqlCommand( insert into tab_bill(code ,sub_code,name 和 amount)选择< pre>代码,sub_code,name 和金额来自 tab_initial 其中代码= 66& quot;, CON);
int q = cmd.ExecuteNonQuery();
我希望 增加instalment_no 按 1 来自 tab_initial(所选行至 插入)只要此输入查询触发 所选行..
解决方案
您可以将id列定义为IDENITY - http://msdn.microsoft.com/en-us/library/ms186775.aspx [ ^ ]
如果这样做,SQL将在每个插入上增加其值......
SqlCommand cmd = new SqlCommand(更新tab_bill set instalment_no = instalment_no + 1
选择代码,子代码,名称和金额来自tab_initial,其中code = 66;,con);
int q = cmd.ExecuteNonQuery();
SqlCommand cmd = new SqlCommand(insert into tab_bill(code,sub_code,name and amount) select <pre>code,sub_code,name and amount from tab_initial where code=66 ", con);
int q = cmd.ExecuteNonQuery();
I want to increment instalment_no by 1 from tab_initial(selected rows to insert)whenever this enter query will trigger from selected rows..
解决方案
You may define the id column as IDENITY - http://msdn.microsoft.com/en-us/library/ms186775.aspx[^]
If you do so SQL will increment its value on each and every insert...
SqlCommand cmd = new SqlCommand(update tab_bill set instalment_no=instalment_no+1 select code,sub_code,name and amount from tab_initial where code=66;,con); int q = cmd.ExecuteNonQuery();
这篇关于执行插入查询时如何增加行ID 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文