从其他用户使用的另一个表中获取ID [英] get ID from another table unused with another users

查看:69
本文介绍了从其他用户使用的另一个表中获取ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为商店编写网络程序

i有两张桌子



 TblSellDocument 
IDDocSell int 未选中密钥 IDentity
IDAccount int 未选中
IDOC int 未选中
IDUser int 未选中
IDCustomer int 未选中
Datein datetime 未选中
SumPrice bigint 未选中
状态未选中

TblSellProduct
IDsell int 未选中 key IDentity
IDDocSell INT 未选中 foreign key
IDStuff int 未选中
编号 int 未选中
SellPrice bigint 未选中
折扣 bigint 未选中
SellMultiplePrice bigint 未选中





现在我想设计一个表格来插入数据但是当我想要填写TblSellProduct我不知道如何找到TblSellDocument.IDDocSell

IDDocSell必须未使用和其他用户一起使用

我很困惑

这种方式是否正确?

解决方案

你是使用SQL服务器:如果是这样,您可以在插入新行时将身份规范设置为自动递增。其他数据库具有类似功能。否则,您需要使用'select distinct'查询来获取已使用ID的列表。

在表单中,您可以将ID留空,直到创建它或者您可以将下一个ID保留为空ID。


如果DocSell没有自动增量,请尝试使用MAX + 1公式增加值

@@ IDENTITY



它返回在当前会话中为所有范围生成的最后一个标识值。



让我解释一下这...假设我们在表上创建一个插入触发器,在另一个表中插入一行并生成一个标识列,然后@@ IDENTITY返回由触发器创建的标识记录。

SCOPE_IDENTITY



它返回为当前会话中的任何表和当前范围生成的最后一个标识值。



让我解释一下......假设我们在表上创建一个插入触发器,在另一个表中插入一行生成标识列,然后SCOPE_IDENTITY结果不受影响但如果触发器或用户定义的函数在生成该值的同一个表上受到影响,则返回该标识记录,然后SCOPE_IDENTITY返回由触发器或用户定义创建的标识记录函数。

IDENT_CURRENT



它返回在任何会话和任何范围内为特定表生成的最后一个标识值。



换句话说,我们可以说它不受范围和会话的影响,它只取决于特定的表并返回在任何会话或范围中生成的表相关标识值。



来源 ^ ]

i want to write network program for store
i have two tables

TblSellDocument
IDDocSell	int	Unchecked key and IDentity
IDAccount	int	Unchecked
IDOC	int	Unchecked
IDUser	int	Unchecked
IDCustomer	int	Unchecked
Datein	datetime	Unchecked
SumPrice	bigint	Unchecked
Status	bit	Unchecked 

TblSellProduct
IDsell	int	Unchecked key and IDentity
IDDocSell	int	Unchecked foreign key
IDStuff	int	Unchecked
Number	int	Unchecked
SellPrice	bigint	Unchecked
Discount	bigint	Unchecked
SellMultiplePrice	bigint	Unchecked 



now i want design a form for insert data but when i want fill TblSellProduct i don't know how can I find TblSellDocument.IDDocSell
IDDocSell must unused with other users
I'm so confuse
this way is correct or not ?

解决方案

Are you using SQL server: if so you can set Identity Specification to auto increment when new rows are inserted. Other databases have similar features. Otherwise you'd need to use a 'select distinct' query to get a list of used IDs.
In the form, you can leave ID blank until it has been created or can you put the next available ID.


If there is no auto increment of DocSell, try using MAX + 1 formula to increment the value


@@IDENTITY

It returns the last identity value generated for any table in the current session, across all scopes.

Let me explain this... suppose we create an insert trigger on table which inserts a row in another table with generate an identity column, then @@IDENTITY returns that identity record which is created by trigger.
SCOPE_IDENTITY

It returns the last identity value generated for any table in the current session and the current scope.

Let me explain this... suppose we create an insert trigger on table which inserts a row in another table with generate an identity column, then SCOPE_IDENTITY result is not affected but if a trigger or a user defined function is affected on the same table that produced the value returns that identity record then SCOPE_IDENTITY returns that identity record which is created by trigger or a user defined function.
IDENT_CURRENT

It returns the last identity value generated for a specific table in any session and any scope.

In other words, we can say it is not affected by scope and session, it only depends on a particular table and returns that table related identity value which is generated in any session or scope.

source^]


这篇关于从其他用户使用的另一个表中获取ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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