具有相同用户ID的数据库中的重复值 [英] Duplicate Value In Database With Same User Id

查看:77
本文介绍了具有相同用户ID的数据库中的重复值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了一个具有s_no,user_name,Phone_number,user_ID ........之类的属性的表,并将插入分为许多部分,因此我首先使用的查询是插入,然后在user_ID匹配的地方进行更新. 并且我使用查询将

Hi All,

I have created a table with attributes like s_no , user_name , Phone_number , user_ID ........ and insertion divided into many parts so first query i used is insert and then update where user_ID matches.
and i use query to insert like

(insert into table (user_name , Phone_number , user_ID where user_ID =textbox1.text)

,其余属性会更新,其中user_ID = @user_ID
类似的问题是,如果用户再次使用相同的user_ID编辑数据库中的内容,则会再次使用相同的user_ID创建新行,并且在这种情况下user_ID必须是唯一的,如果任何用户再次使用相同的user_ID,则新数据将以相同的user_ID更新,而不是创建新行.我知道一定有类似
的查询
如果这样的话

插入

其他

更新

但问题是我对在同一位置使用插入和更新一无所知.

我想使用解决此问题的程序.

任何帮助都将适用.
谢谢

and for the rest of the attributes update where user_ID = @user_ID
something like that but the problem is if user again use the same user_ID to edit something in database there is again a new row created with the same user_ID and for this scenario user_ID must be unique and if any user again use the same user_ID then the new data will be update in the same user_ID instead of new row created. I know there must be query like

if this then

insert

else

update

but the thing is i don''t have any idea about it to use insert and update at the same place.

i want to use procedure for solving this problem.

Any help will be appropriated.
Thanks

推荐答案

做到这一点很简单……

编写程序并检查类似的条件

如果不存在(从UserMaster中选择User_id,其中User_id =''传递用户ID参数)
开始
在此处写入插入语句
END
ELSE
开始
如果数据库中存在User_id,请在此处编写更新语句
END
it is very simple to do that......

write a procedure and check the condition like that

IF Not exists(select User_id, from UserMaster where User_id=''pass the user id parameter)
BEGIN
write here insert statement
END
ELSE
BEGIN
write here update statement if User_id exsists in database
END


您是否忘记了诸如主键"之类的东西???
are you forgetting something like "Primary key"...????


主键"会在尝试时抛出错误两次插入相同的值.或者,您可以使用User_ID进行选择",如果程序找到一个值,然后进行更新,或者如果您希望控制代码中的行为,则进行插入.
"Primary Key" will throw an error if you try to insert the same value twice. Or you could to a "select" using the User_ID and if the program finds a value, then update, else insert if you prefer to control the behaviour in the code.


这篇关于具有相同用户ID的数据库中的重复值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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