如何在Sql Server中调整我的表的标识列 [英] How Do I Adjust Identity Column Of My Table In Sql Server

查看:209
本文介绍了如何在Sql Server中调整我的表的标识列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

我正在创建我的桌子现金簿(这是我的会计软件的一部分)。在那个

i已经创建了我的表格



创建表现金簿(cno int主键,voucherno int identity(1,1),date1 date,perticulars varchar(100),amount bigint,total bigint)





当我们在该表中插入值时一切正常

但我的客户要求是,他可以在该表中插入过时的条目,就像那样

Hello everyone
I am creating my table cashbook (which is the part of my accounting software). in that
i already created my table as

create table cashbook(cno int primary key , voucherno int identity(1,1), date1 date , perticulars varchar(100),amount bigint , total bigint)


when we inserting values in that table all going ok
but my customer requirement is that can he insert back dated entries in that table means like that

cno |  voucherno | date1| perticulars  |amount |total
1|1|2015-11-02|for personal |2000|6000  <br>
2|2|2015-11-03| for office expences | 4000 | 10000 <br>
3|3|2015-11-03|for office | 2000 |8000 

Now my customer requirement is that can he insert another value at voucherno 2  and date = 2015-11-03
then according to him our table will be
<pre lang="vb">cno |  voucherno | date1| perticulars  |amount |total
1|1|2015-11-02|for personal |2000|6000  &lt;br&gt;
2|2|2015-11-03| for office expences | 4000 | 10000 &lt;br&gt;
4|3|2015-11-02|for personal expences | 4000 | 14000 
3|4|2015-11-03|for office | 2000 |16000 &lt;br&gt;
</pre>







就像当我插入任何值时它会自动添加最后一笔金额+当前金额但是当我们可以插入过时的条目时,它遵循相同的规则





现在我的问题是如何调整最后的标识列值记录,当前记录和下一个记录




like that when i insert any value it automatically add the the last amount + current amount but when we can insert back dated entry it follows same rule


now my question is how do i adjust the identity column value for last record , current record and next all record

推荐答案

您可以使用IDENTITY_INSERT ON



查看此文章了解更多详情 -

如何在SQL Server中向标识列插入值 [ ^ ] br />


希望,它有帮助:)
You can insert explicit value in to an identity column using IDENTITY_INSERT ON

Check this article for further details-
How to insert values to identity column in SQL Server[^]

Hope, it helps :)


这篇关于如何在Sql Server中调整我的表的标识列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆