检查重复并报告错误 [英] Check for Duplicates and Report Error

查看:96
本文介绍了检查重复并报告错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个存储的proc以便在表中插入一些数据...但是在此之前,我想检查该记录是否已经存在于表中.如果是,那么它应该显示一些消息,例如重复数据"

我正在从前端插入数据.

还有如何在前端捕获该消息.

请帮我.

在此先谢谢您.

I want to write a stored proc to insert some data in a table...but before that I want to check whether that record is already present in table or not. If yes then it should display some message like "duplicate data"

I am inserting the data from front end.

And also how to catch that msg in front end.

Please help me.

Thanks in advance.

推荐答案

好吧,基于以下问题:
1.一种好方法是在表本身上施加唯一约束!插入前会检查.
2.如果要在UI中进行操作,则获取所有数据并进行循环检查.但这将是一个漫长的过程.

选项1对您有好处.

更新:
在这里查看: MSDN-唯一约束 [
Well, based on the issue:
1. One of the good ways would be to put unique constraint on the table itself! It will check before inserting.
2. If you want to do it in UI, then get all data and check in a loop. But that would be a lengthy procedure.

Option1 is good for you.

UPDATE:
Look here: MSDN - UNIQUE Constraints[^


这篇关于检查重复并报告错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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