declare @AlyID int
select @AlyID=AlyID from tableA WHERE comid=1 --查看表是否存在数据 if isnull(@AlyID,'')!='' and @AlyID !='' --存在数据,进行修改 begin UPDATE tableA SET columnA='' WHERE columnA =1 --修改 SELECT @AlyID as AlyID END ELSE begin insert into tableA( )values( ) --新增 select @@identity as AlyID --得到自增ID END