Finding duplicate rows in the database
{{
Information gleaned from Microsoft KB article: How to remove duplicate rows from a table in SQL Server
When you allow duplicated rows in a database that aren't expected and shouldn't be allowed, it's a flag saying that you need a unique index on the table to prevent duplicate rows to be added in the first place.
The first step to fixing the problem is to find and fix the duplicated rows.
The second step is to add an index once the existing duplicate rows have been dealt with, so that the problem won't occur in the future.
If you have a Users
table, which has an Email
column, you will likely want that Email
column to have a unique index. You can find the duplicated emails (and the number of times each email occurs) using this query:
Microsoft.Playwright.PlaywrightException: Error: The language "mysql" has no grammar.
at Object.highlight (http://127.0.0.1:41899/main.js:3978:11)
at eval (eval at evaluate (:226:30), :2:18)
at UtilityScript.evaluate (:233:19)
at UtilityScript. (:1:44)
at Microsoft.Playwright.Transport.Connection.InnerSendMessageToServerAsync[T](ChannelOwnerBase object, String method, Dictionary`2 dictionary, Boolean keepNulls) in /_/src/Playwright/Transport/Connection.cs:line 209
at Microsoft.Playwright.Transport.Connection.WrapApiCallAsync[T](Func`1 action, Boolean isInternal) in /_/src/Playwright/Transport/Connection.cs:line 535
at Microsoft.Playwright.Core.Frame.EvaluateAsync[T](String script, Object arg) in /_/src/Playwright/Core/Frame.cs:line 548
at SiteGen.Extensions.Markdown.Prism.PrismHost.Highlight(String source, String language)
at SiteGen.Extensions.Markdown.Prism.PrismCodeBlockRenderer.Write(HtmlRenderer renderer, PrismCodeBlock obj)
Which may return something like this:
NumberOfDuplicates | |
---|---|
joe@bloggs.com |
3 |
spammer@spamilicious.com |
13 |
etc |
Now you can go about carefully resolving the duplicates, then adding the constraints to that column to prevent duplicates occurring again.