Oracle中如何检查所有字段是否唯一?
Oracle中如何检查所有字段是否唯一?
How to check if all fields are unique in Oracle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Oracle中如何检查所有字段是否唯一?
How to check if all fields are unique in Oracle?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(3)
如果出现次数大于 1(即它们不是唯一的),这将返回所有 myColumn 值及其出现次数。
如果此查询的结果为空,则此列中具有唯一值。
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.
执行此操作的一个简单方法是使用 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.
一种方法是创建唯一索引。
如果索引创建失败,则您有现有的重复信息,如果插入失败,它将产生重复...
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...