Abaixo vou colocar um script que demonstra como deletar dados duplicados de uma tabela em um banco de dados SQL Server, neste exemplo a tabela tem uma coluna ID como IDENTITY e outra coluna como VARCHAR onde estão os valores duplicados.
Vejam o Script SQL:
/* Criando a tabela */ CREATE TABLE MinhaTabela (ID INT, CodVarchar VARCHAR(10)) Go /*Inserindo dados na tabela*/ INSERT INTO MinhaTabela (ID, CodVarchar) SELECT 1, 'VALOR1' UNION ALL SELECT 2, 'VALOR2' UNION ALL SELECT 3, 'VALOR3' UNION ALL SELECT 4, 'VALOR3' UNION ALL SELECT 5, 'VALOR3' UNION ALL SELECT 6, 'VALOR4' UNION ALL SELECT 7, 'VALOR5' GO /*Validando todos os dados da tabela*/ SELECT * FROM MinhaTabela GO /*Validando apenas os valores duplicados*/ SELECT CodVarchar, COUNT(*) Total FROM MinhaTabela GROUP BY CodVarchar GO /*Deletando apenas os valores duplicados*/ DELETE FROM MinhaTabela WHERE ID NOT IN( SELECT MAX(ID) FROM MinhaTabela GROUP BY CodVarchar ) GO /*Apagando a tabela*/ DROP TABLE MinhaTabela GO
Blackjack, additionally known as twenty-one, is just one of one of the most popular gambling…
If you are a fan of online gambling, then you must have come across gry…
On the internet online casinos have transformed the betting industry, enabling players to vegas.hu online…
Casinos online offer free spins to draw new customers. These bonuses are usually very profitable,…
In recent times, online casino sites have actually obtained enormous appeal among gamers, providing a…
Bitcoin, the most preferred cryptocurrency worldwide, has reinvented lots of industries, including the on baixar…