SQL SERVER ayni olan kayitlari silme

Selam

Aşağıdaki aynı kayıtları bulup silme scripti

SELECT a+b+c AS val
INTO dbo.rmtemp
FROM (SELECT 0 a UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) a
, (SELECT 0 b UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) b
, (SELECT 0 c UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3) c
? Olanları listele
SELECT val,COUNT(*) row_count FROM dbo.rmtemp GROUP BY val
? Tek Kayıta düşürme

SET ROWCOUNT 1
? birden fazla olan kayıtları sil
WHILE (SELECT TOP 1 val FROM dbo.rmtemp GROUP BY val HAVING COUNT(*) > 1) IS NOT NULL
DELETE FROM dbo.rmtemp WHERE val IN (SELECT TOP 1 val FROM dbo.rmtemp GROUP BY val HAVING COUNT(*) > 1);
SET ROWCOUNT 0
? Unique olmasını sağla
SELECT val,COUNT(*) row_count FROM dbo.rmtemp GROUP BY val
? Temizle

DROP TABLE dbo.rmtemp
GO

Ayrıca Buna Bakabilirsiniz

SQL Server: Login failed for User ‘NT AUTHORITY\ANONYMOUS LOGON

SQL Server: Login failed for User ‘NT AUTHORITY\ANONYMOUS LOGON’ Merhaba bu hata www.sqlogren.com sitesindeki en …