UPDATE tab1022zhm SET ID =FROM (SELECT ROW_NUMBER() OVER (ORDER BY id) ROW,comName FROM dbo.tab1022zhm) a WHERE tab1022zhm.comName=a.comName