Hot File

How to Detecting and Deleting Duplicate Records in SQL Server 2005 and Above

View: 288    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: MySQL   Fields: Other

9 point/3 review File has been tested

Download   how-to-detecting-and-deleting.rar (23.73 KB)

You need to Sign In to download the file how-to-detecting-and-deleting.rar
If you do not have an account then Sign up for free here

Download error   Report copyright violation

Most of the time, we encounter duplicate records in our database. And it's not easy to delete it if you don't have enough knowledge about SQL Statement.

Introduction

Most of the time, we encounter duplicate records in our database. And it's not easy to delete it if you don't have enough knowledge about SQL Statement.

This code will help you detect and delete duplicate records in SQL Server 2005 and above.

(These commands only works on sql server 2005 or higher)

Create table

CREATE TABLE example(id INT IDENTITY(1,1),name VARCHAR(20),class VARCHAR(20));

Insert Records

INSERT INTO example(name,class)VALUES('tam','1');
INSERT INTO example(name,class)VALUES('tam','1');
INSERT INTO example(name,class)VALUES('ram','1');
INSERT INTO example(name,class)VALUES('tam','2');
INSERT INTO example(name,class)VALUES('tam','1');
INSERT INTO example(name,class)VALUES('ram','1');
INSERT INTO example(name,class)VALUES('ram','2');
INSERT INTO example(name,class)VALUES('ram','2');

Here we are inserting records. It contains duplicates also.For the detection and Deletion of duplicates we use Common Table Expressions (CTE).

Detecting Duplicates :

SELECT ROW_NUMBER() OVER(partition BY name,class ORDER BY id) AS dup FROM example;

If you get more than 1 in any of the columns, that means you have duplicate records in your Table.

Deleting Duplicates :

WITH sample1
AS
(SELECT ROW_NUMBER() OVER(partition BY name,class ORDER BY id) AS dup FROM example)
DELETE FROM sample1 WHERE dup>1
GO

With this code snippet you can delete duplicates from your table.
(Here Sample1 is any name, it is a CTE name).

How to Detecting and Deleting Duplicate Records in SQL Server 2005 and Above

How to Detecting and Deleting Duplicate Records in SQL Server 2005 and Above Posted on 07-01-2016  Most of the time, we encounter duplicate records in our database. And it's not easy to delete it if you don't have enough knowledge about SQL Statement. 3/10 288

Comment:

To comment you must be logged in members.

Files with category

  • SQL Query to Find Nth Highest Salary of Employee with java

    View: 367    Download: 0   Comment: 0   Author: none  

    SQL Query to Find Nth Highest Salary of Employee with java

    Category: MySQL
    Fields: Other

    0/0 review
    This is a very common interview question if you are going for the role at junior level. Most of the people learn it character by character, but few understand how this query works.

  • World OOP With PHP and MySQL

    View: 1127    Download: 0   Comment: 0   Author: none  

    World OOP With PHP and MySQL

    Category: MySQL
    Fields: Other

    0.32142857142857/14 review
    Setting up the skeleton of our class is fairly simple once we figure out exactly what we need.

  • How to Build a Newsletter System With PHP and MySQL

    View: 1476    Download: 0   Comment: 0   Author: none  

    How to Build a Newsletter System With PHP and MySQL

    Category: MySQL
    Fields: Other

    1.125/4 review
    When starting any project, I like to layout the folders before I start coding, so lets do that now.

  • Top 20+ MySQL Best Practices that can not be ignored

    View: 1064    Download: 0   Comment: 0   Author: none  

    Top 20+ MySQL Best Practices that can not be ignored

    Category: MySQL
    Fields: Other

    1.6666666666667/3 review
    Database operations often tend to be the main bottleneck for most web applications today.

  • Create a PHP/MySQL Powered Forum from Scratch

    View: 1295    Download: 0   Comment: 0   Author: none  

    Create a PHP/MySQL Powered Forum from Scratch

    Category: MySQL
    Fields: Other

    1.5/3 review
    In this tutorial, we're going to build a PHP/MySQL powered forum from scratch.

  • Triggers Introduction to MySQL

    View: 385    Download: 0   Comment: 0   Author: none  

    Triggers Introduction to MySQL

    Category: MySQL
    Fields: Other

    1.6666666666667/3 review
    I would guess, even armed with this knowledge, that a good many of you are not taking advantage of triggers with MySQL.

  • How to Stored Procedures in MySQL 5

    View: 384    Download: 0   Comment: 0   Author: none  

    How to Stored Procedures in MySQL 5

    Category: MySQL
    Fields: Other

    2.25/2 review
    MySQL 5 introduced a plethora of new features - stored procedures being one of the most significant. In this tutorial, we will focus on what they are, and how they can make your life easier.

  • The strength of the PDO and. MySQLi: Which Should You Use?

    View: 395    Download: 0   Comment: 0   Author: none  

    The strength of the PDO and. MySQLi: Which Should You Use?

    Category: MySQL
    Fields: Other

    1.5/3 review
    When accessing a database in PHP, we have two choices: MySQLi and PDO. So what should you know before choosing one?

 
Newsletter Email

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd