过程“分配值问题”

时间:2012-10-08 19:38:07

标签: sql-server identity procedure

  

可能重复:
  How to get the primary key of the last row inserted into the table

我有两张桌子:

Downloaded(Id,MovieName,DownloadedBy)
Movie(ID,Rating,...)

Downloaded(id)identity (1,1)Movie(Id)Downloaded(id)的外键 现在我需要同时插入两个程序

alter proc sp_Insert
@name varchar (50),
@year int,
@type varchar (50),
@rating int,
@available bit
AS
Insert into Downloaded (MovieName) values (@name)
declare @id int
select Id=@id
from Downloaded
where MovieName=@name
Insert into Movie values (@id,@year,@type,@rating,@available) 

现在我的问题是从SELECT @id获取null的{​​{1}}值,这意味着id没有获取新的身份值。

那么为了使Downloaded(id)获取@id的标识值,该怎么做是有任何类型的块执行或我不知道可能交易

请耐心等待我,我还是新人

0 个答案:

没有答案