SQL插入查询以防止重复数据 [英] SQL Insert Query to prevent duplicate data

查看:561
本文介绍了SQL插入查询以防止重复数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是SQL查询以防止在数据库表中重复插入数据

what is the SQL query to prevent duplicate insertion of data in a data base table

推荐答案

您好,

您可以使用 EXISTS 检查此链接 MSDN [ ^ ]

< a href =http://www.techonthenet.com/sql/exists.php>示例 [ ^ ]

最好的问候

M.Mitwalli
Hi ,
You can use EXISTS Check this link MSDN[^]
Example [^]
Best Regards
M.Mitwalli


我会建议您在表格中使用主键(或设置唯一约束)。

这样可以防止重复输入。



如何将UNIQUE约束应用于现有SQL列 [ ^ ]可能会帮助您入门。
I would recommend you have a primary key (or setup a unique constraint) in your table.
This would prevent duplicate entry.

How to apply UNIQUE constraints to existing SQL columns[^] might help you get started.


因为您没有

1)SQL的状态类型( MySQL,Oracle,SQL Server ....)

2)举例说明你尝试过的事情

我会给你一个SQL Server的提示。查看 LEFT JOIN

Since you did not
1) State type of SQL (MySQL, Oracle, SQL Server....)
2) Give example of what you have tried
I will give you a hint for SQL Server. Look at LEFT JOIN
INSERT INTO Table2 (variable list)
SELECT variable list 
FROM Table1 
LEFT JOIN Table2 
ON Table1.keyfield = Table2.keyfield 
WHERE Table2.keyfield IS NULL;


这篇关于SQL插入查询以防止重复数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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