SQL唯一记录不是列? [英] SQL Unique Record not column?

查看:166
本文介绍了SQL唯一记录不是列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法插入整个记录是唯一的SQL数据库?我知道你可以制作主键和唯一的列,但这不是我想要的。



在不重载数据库的情况下,最好的方法是什么?我已经看到一个子查询,你使用WHERE NOT EXISTS()



我只是想知道最有效的插入记录的方法,以便没有重复的EXACT相同的记录。



提前谢谢!

解决方案

你知道如何在列上的唯一索引。



只需将所有列应该在一起是唯一的:

 在tablename(columnone,columntwo,columnthree)上创建唯一索引foo 
;

请注意,需要这样做可能表示您的表格没有被足够的标准化。 p>

Is there a way to insert into an SQL database where the whole record is unique? I know you can make primary keys and unique columns, but that is not what I want.

What is the best way of doing this without overloading the database? I have seen a sort of subquery where you use "WHERE NOT EXISTS ()"

I just want to know the most efficient way of inserting a record so that there are no duplicates of the EXACT same record.

Thank you in advance!

解决方案

You know how to make a unique index on a column.

Just make that on all the columns that should, together, be unique:

create unique index foo 
on tablename(columnone, columntwo, columnthree);

Note that the need to do this may be an indication that your table is not sufficiently normalized.

这篇关于SQL唯一记录不是列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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