We can delete duplicate records in the following ways:
Example: Table name: dbo. Variety Description $, field includes: ID_PK, breed name, trait standard number, code, first create a table that is the same as the original table structure:
Copy Code code as follows:
Select * into Tmpa from dbo. Breed Description $ where 1=2--created
in datasheet, breed name, trait standard number These two fields cannot be With duplicate values, execute the following script:
declare @VarietyName nvarchar (255),
@StdCharCode nvarchar (255),
@iCount int
Set @iCount = 0;
Declare insert_distinct_cursor cursor for
Select breed name, trait standard number from dbo. Breed Description $ GROUP by breed name, trait standard number
Open Inse Rt_distinct_cursor
FETCH NEXT from Insert_distinct_cursor to @VarietyName, @StdCharCode
while (@ @fetch_status <>-1
Begin
IF (@ @fetch_status <>-2)
begin
INSERT INTO Dbo.tmpa (breed name, trait standard number, code) SE Lect top 1 Breed name, trait standard number, code from dbo. Breed description $ where breed name = @VarietyName and trait standard number = @StdCharCode;
Set @iCount = @iCount +1;
End
FETCH NEXT from Insert_distinct_cursor to @VarietyName, @StdCharCode
End
Close Insert_dis Tinct_cursor
deallocate insert_distinct_cursor
Print @iCount