插入查询,表中不需要相同的数据. [英] insert query, same data not want in table.

查看:64
本文介绍了插入查询,表中不需要相同的数据.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我插入数据时,
如果表中有相同的数据,则我想报错味精.
我该怎么做.

hi folks,

when i insert data,
if the same data is in the table then i want error msg.
how can i do these.

推荐答案

这实际上取决于您认为重复"的数据.

如果只有一个字段不能重复,则需要将该字段设置为主键.

如果您有两个或三个这样的字段,请创建一个复合主键.

然后,当您尝试输入重复的值时.数据库将自动生成错误消息.
It really depends upon what you consider ''duplicate'' data.

If you have just one field that should not be a duplicate what you need to do is to set that field as a primary key.

If you have two or three fields like this, create a composite primary key.

Then when you try to enter duplicate values. the database will automatically generate error messages.


您需要自行处理.在插入数据之前,请查询是否存在准确的数据,如果找到匹配项,则需要返回错误,否则可以插入数据.
You need to handle that on your own. Before you insert the data, query if exact data exist, if you found a match then you need to return an error, else you are good to insert the data.


直到我了解您的问题是,您不想在表中重复输入吗?

如果是这样,则对列使用唯一约束.
till what I understood from your problem, is u don''t want duplicate entry in your table.

If so then use unique constraint on a column.


这篇关于插入查询,表中不需要相同的数据.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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