ALTER PROCEDURE [dbo].[OA_RemoveProject] @Password nvarchar(30), --这是传入的参数 @ProjectNo nvarchar(8) AS DECLARE @ProjectId int --这是声明的参数。 DECLARE @Count int BEGIN IF UPPER(@Password)=‘FEIFEIDEMAO‘ BEGIN SET @Count=(SELECT COUNT(*) FROM DwProject WHERE [email protected]) if @Count=1 BEGIN SET @ProjectId=(SELECT Id FROM DwProject WHERE [email protected]) Delete From DwProject Where [email protected] Delete From DwTask Where [email protected] Delete From DwProjectRelatedPersonnel Where [email protected] Delete From DwProjectQuestion Where [email protected] Delete From DwProjectFile Where [email protected] 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 NOWAIT END
需求:ID主键,非查询不可取到。但是ProjectNo可以看到。实现通过ProjectNo删除数据,以及关联表数据。(参数是 密码和要删除的项目编号)
时间: 2025-01-03 01:06:28