ALTER PROCEDURE [dbo].[OA_RemoveProject]@Password nvarchar(30), --这是传入的参数 @ProjectNo nvarchar(8)ASDECLARE @ProjectId int --这是声明的参数。DECLARE @Count intBEGIN IF UPPER(@Password)='FEIFEIDEMAO' BEGIN SET @Count=(SELECT COUNT(*) FROM DwProject WHERE ProjectNo=@ProjectNo) if @Count=1 BEGIN SET @ProjectId=(SELECT Id FROM DwProject WHERE ProjectNo=@ProjectNo) Delete From DwProject Where Id=@ProjectId Delete From DwTask Where LinkId=@ProjectId Delete From DwProjectRelatedPersonnel Where ProjectId=@ProjectId Delete From DwProjectQuestion Where ProjectId=@ProjectId Delete From DwProjectFile Where ProjectId=@ProjectId END ELSE IF @Count>1 RAISERROR(N'项目编码对应多个主键ID,无法删除!',11,5)WITH NOWAIT ELSE RAISERROR(N'未找到项目编号!',11,5)WITH NOWAIT END ELSE RAISERROR(N'密码错误,重新执行!',11,5)WITH NOWAITEND
需求:ID主键,非查询不可取到。但是ProjectNo可以看到。实现通过ProjectNo删除数据,以及关联表数据。(参数是 密码和要删除的项目编号)