Delete Script

declare @projectidmax int,@curprojectid int;

select @projectidmax=max(fk_project_id) from budget;

while @curprojectid<@projectidmax 
begin 
declare @budgetidmax int;
select @budgetidmax=max(budget_id) from budget where fk_project_id=@curprojectid;
delete from budget where (fk_project_id=@curprojectid and budget_id<@budgetidmax); 
set @curprojectid=@curprojectid+1;
end----It doesnt pass test

--------------------------------------------------------------------------------------------------------------------------------------

 

 

 

declare @projectidmax int,@curprojectid int;

select @projectidmax=max(fk_project_id) from budget;
set @curprojectid=1;
while @curprojectid<@projectidmax 
begin 
declare @budgetidmax int;
select @budgetidmax=max(budget_id) from budget where fk_project_id=@curprojectid;
delete from budget where ((fk_project_id=@curprojectid) and (budget_id<@budgetidmax)); 
set @curprojectid=@curprojectid+1;
end----test successfully

 

你可能感兴趣的:(script)