如何在将重复值插入表格时进行检查 [英] How can i put a check for while inserting duplicate value into table

查看:69
本文介绍了如何在将重复值插入表格时进行检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Work_Details表包含

Work_Name



intigrated

stringvalue

CharValue



现在我需要一个查询,如果我给出重复的名字,将返回一些东西。

意味着如果我再给CharValue它会不插入表格。

如何在插入表格之前进行检查?

I have a Work_Details table containing
Work_Name

intigrated
stringvalue
CharValue

Now I need a query that will return something if I give duplicate name.
Means if I give CharValue again it will not insert in the table.
How can I put a check before inserting in to the table?

推荐答案

你不需要在INSERT之前检查。



使其中一个字段成为唯一键,然后当您尝试INSERT进入数据库时​​,它将无法告诉您该记录已存在。
You don''t need to check before the INSERT.

Make one of the fields a unique key, then when you attempt to INSERT into the database it will fail telling you that that record already exists.


if not exists ( select * from table  where field=value)
begin
put insert query 
end





如果想看到dublicate row



使用



喜欢



从表组中选择计数(*)按(列名)计数(*) )> 1



它将全部录音



and if want to see dublicate row

use

like

select count(*) from table group by (column name ) having count(*)>1

it will all dulicate record


这篇关于如何在将重复值插入表格时进行检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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