Delete multiple methods for the same record in a table

Source: Internet
Author: User
Import data to a temporary table and add a column ID as an index to it.
Then, you can find the maximum index of the same record in this temporary table and insert another table UC_CARDTL_Temp_ForImport.
Delete the column ID in the UC_CARDTL_Temp_ForImport table.
Finally, delete the original table and change the name to the original table name use hos.


If Exists (Select 1 From tempdb. dbo. sysobjects where Name = '# temp_UC_CarDTL' And Xtype = 'U ')
Drop table # temp_UC_CarDTL
Go

Select Identity (int, 1, 1) as ID, * into # temp_UC_CarDTL From UC_CardTL
Go

If Exists (Select 1 From sysobjects where Name = 'uc _ CARDTL_Temp_ForImport 'And Xtype = 'U ')
Drop table UC_CARDTL_Temp_ForImport
Go

Select * into UC_CARDTL_Temp_ForImport From # temp_UC_CarDTL Where ID
In
(
Select Max (ID) From # temp_UC_CarDTL Where 1 = 1 Group By CarName, CarID, Class Having Count (*)> 1
)

Alter Table [UC_CARDTL_Temp_ForImport] Drop Column [ID]
Go
Drop Table UC_CARDTL
Go
Sp_rename 'uc _ CARDTL_Temp_ForImport ', 'uc _ CARDTL'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.