且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用asp.net删除sql server 2008中的重复行

更新时间:2023-02-06 23:13:00

尝试

Try
public static void DeleteDuplicateEntry()
     {        
         using (SqlConnection cn = new SqlConnection("YourConnectionStringName"))
         {
             SqlCommand objComm = new SqlCommand("delete from MainTable where phone_number in (select phone_number from DNC)", cn);
             objComm.CommandType = CommandType.Text;
             cn.Open();
             objComm.ExecuteNonQuery();
         }         
     }


正如你所说的删除数据 - 如果你不想删除整行,而只是从主表中删除电话号码,然后用
As you have said "remove data" - if you do not want to delete the entire row, but just remove the phone number from the Main table then replace the query in the SqlCommand with
update Main SET phone_number = '' FROM main INNER JOIN DNC on Main.phone_number = DNC.phone_number