如何使用插入数据检查数据库中的现有数据 [英] how to check the existing data in database with the inserting data

查看:69
本文介绍了如何使用插入数据检查数据库中的现有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用插入数据检查数据库中的现有数据....

how to check the existing data in database with the inserting data....

推荐答案

如果您想要插入数据,如果它是新的,并且更新它是否已经存在,那么你最好的选择可能是编写一个存储过程来执行它。

确切的过程将取决于你的表以及什么使行存在,但那里这是一个例子: http://forums.asp.net/t/1608207.aspx/1 [ ^ ]
If you mean that you want to insert data if it is new, and update it is it already exists, then your best option is probably to write a stored procedure to do it.
The exact procedure will depend on your table and what makes a row "exist", but there is an example here: http://forums.asp.net/t/1608207.aspx/1[^]


您好b $ b

您必须使用以下版本的存储过程来执行此操作:



Hi
You must use from bellow Stored Procedure for do this:

Create	Procedure	YourStoredProcedureName
@ID		Bigint		
-- and add another parameter here
As
	Begin Try
		Update	YourTableName
			Set	All parameters without ID must be set

			Where	ID	= @ID	

		IF	@@ROWCOUNT	=	0
		Begin
			Insert	YourTableName(All parameters without ID)
				Values(All parameters without ID)
		End
		Select	0
		Return	

	End	Try
	Begin	Catch
		Select	Error_Number() * -1
		Return	
	End	Catch





我希望它对你。



I hope it is helpful for you.


首先,根据我的理解,你的所有问题都不清楚,如果记录不存在,你想插入数据....

< br $>


First off all your question is not clear as per my understanding , you want inserting the data if the record is not exist....


IF NOT EXISTS ( SELECT COL1 FROM TABLE WHERE PK_COL1=@COL1)
BEGIN
   -- INSERT QUERY
END


这篇关于如何使用插入数据检查数据库中的现有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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