Menghapus Redudansi Data SQL Server

DECLARE @Hitung int
DECLARE @Kode char(5)
DECLARE @Nama varchar(50)

DECLARE kursor_duplikasi CURSOR FAST_FORWARD FOR
SELECT Kode, Nama, COUNT(*) – 1
FROM contoh
GROUP BY Kode, Nama
HAVING COUNT(*) > 1

OPEN kursor_duplikasi

FETCH NEXT FROM kursor_duplikasi INTO @Kode, @Nama, @Hitung

WHILE @@FETCH_STATUS = 0
BEGIN
SET ROWCOUNT @Hitung
DELETE FROM contoh WHERE Kode = @Kode AND Nama = @Nama
SET ROWCOUNT 0
FETCH NEXT FROM kursor_duplikasi INTO @Kode, @Nama, @Hitung
END

CLOSE kursor_duplikasi
DEALLOCATE kursor_duplikasi

About Administrator

ok deh
This entry was posted in Komputer. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s