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
Port video games have actually long been a popular type of entertainment, providing exhilarating gameplay…
When it pertains to online gambling, safety needs to be a top issue for every…
There are many reasons to play no-cost online casino games in the coming year. The…
On the internet casinos have acquired tremendous appeal in recent times, offering gamers with the…
Welcome to our useful post concerning the very best casino site game! Whether you're a…
The random number generator (or RNG) is the program that generates the outcome of every…