简体   繁体   English

如何验证特定表字段的内容是否明确?

[英]How to verify if the content of a specific table field is univocal?

I am not very into database and I have the following problem: I have a table with many many records and I have to verify if in this table some records have the same value for a specific field (so I have to check if a specific field is not univocal) 我对数据库不是很了解,并且遇到以下问题:我有一个包含许多记录的表,并且我必须验证该表中的某些记录是否对特定字段具有相同的值(因此,我必须检查特定的字段不单薄)

So for example I have a table named MaliciousCodeAlertDocument and I want verify if the Title field is an univocal field or not. 因此,例如,我有一个名为MaliciousCodeAlertDocument的表,并且我想验证“ 标题”字段是否为单义字段。

What can I do to it? 我该怎么办? I am thinking that maybe I can use count and group by but I have many doubt about how do it in practice. 我在想,也许我可以使用计数分组依据,但是我对如何在实践中产生疑问。

Can you help me? 你能帮助我吗?

Tnx TNX

Assuming you are using SQL Server and not mysql, you can do it with count and group by: 假设您使用的是SQL Server,而不是mysql,则可以使用count和group by来实现:

SELECT Title, COUNT(1) AS TitleCount
FROM MaliciousCodeAlertDocument
GROUP BY Title
HAVING COUNT(1) > 1

This will only return records where the Title field is repeated, so if it returns no records, the field is "univocal". 这将仅返回重复“标题”字段的记录,因此,如果不返回任何记录,则该字段为“唯一”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM