Oracle中如何检查所有字段是否唯一?

发布于 2024-09-29 00:53:37 字数 27 浏览 1 评论 0原文

Oracle中如何检查所有字段是否唯一?

How to check if all fields are unique in Oracle?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

吾性傲以野 2024-10-06 00:53:37
SELECT myColumn, COUNT(*)
FROM myTable
GROUP BY myColumn
HAVING COUNT(*) > 1

如果出现次数大于 1(即它们不是唯一的),这将返回所有 myColumn 值及其出现次数。

如果此查询的结果为空,则此列中具有唯一值。

SELECT myColumn, COUNT(*)
FROM myTable
GROUP BY myColumn
HAVING COUNT(*) > 1

This will return to you all myColumn values along with the number of their occurence if their number of occurences is higher than one (i.e. they are not unique).

If the result of this query is empty, then you have unique values in this column.

南薇 2024-10-06 00:53:37

执行此操作的一个简单方法是使用 DBMS_STATS 分析表。完成后,您可以查看 dba_tables...查看 num_rows 列。查看 dab_tab_columns。将每列的 num_distinct 与行数进行比较。如果您担心影响大表上的生产系统,那么这是一种无需执行全表扫描即可完成您想要的操作的方法。如果您想要直接结果,请按照其他人的建议,通过使用分组依据对表运行查询。

An easy way to do this is to analyze the table using DBMS_STATS. After you do, you can look at dba_tables... Look at the num_rows column. The look at dab_tab_columns. Compare the num_distinct for each column to the number of rows. This is a round about way of doing what you want without performing a full table scan if you are worried about affecting a production system on a huge table. If you want direct results, do what the the others suggest by running the query against the table with a group by.

流云如水 2024-10-06 00:53:37

一种方法是创建唯一索引。
如果索引创建失败,则您有现有的重复信息,如果插入失败,它将产生重复...

one way is to create a unique index.
if the index creation fails, you have existing duplicate info, if an insert fails, it would have produced a duplicate...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文