Sometimes it is necessary to remove duplicate records from a table.
You can get the idea how to do this with examining this SQL statements. This is an example that removes duplicate phonenumbers from a phonebook table.
sam47221369,
2008-04-19 (first published: 2008-02-22)
Sometimes it is necessary to remove duplicate records from a table.
You can get the idea how to do this with examining this SQL statements. This is an example that removes duplicate phonenumbers from a phonebook table.
--Show Duplicate Phonenumbers in Phonebook SELECT phonenumber, COUNT(*) FROM phonebook GROUP BY phonenumber HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC --Delete All Duplicate Records from Phonebook CREATE TABLE #tmp ( [phonenumber] [varchar] (30), [firstname] [varchar] (30), [lastname] [varchar] (30), [company] [varchar] (100) ) --Create a unique index on phonenumber column --"WITH IGNORE_DUP_KEY" is the key CREATE UNIQUE INDEX unqT ON #tmp (phonenumber) WITH IGNORE_DUP_KEY INSERT INTO #tmp SELECT [phonenumber] , [firstname] , [lastname] , [company] FROM phonebook --Truncate original table TRUNCATE TABLE phonebook INSERT INTO phonebook SELECT * FROM phonebook DROP TABLE #tmp
For most DBAs, normalization is an understood concept, a bread and butter bit of knowledge. However, it is not at all unusual to review a database design by a development group for an OLTP (OnLine Transaction Processing) environment and find that the schema chosen is anything but properly normalized. This article by Brian Kelley will give you the core knowledge to data model.
2003-01-13
18,069 reads
What's this error:Arithmetic overflow error converting IDENTITY to data type int? It was a new one to me, but read on to find out what it means.
2002-10-14
6,900 reads
This article shows you how to design the storage for email addresses, how to validate email addresses, how to retrieve demographic information from email addresses efficiently, using computed columns and indexes. It also covers the security aspect of dealing with email addresses.
Binary data can be stored as integers in a table. This article explains how to query an integer field to return the bits represented by the integer.
2002-06-28
4,567 reads
This article demonstrates how to store checkbox results as integers in a database...perfect for surveys!
2002-06-27
4,427 reads