我有两个表。 dbo.Emp的EmpID(PK)| 名称| typeid的(FK)
dbo.EmpType typeid的(PK)| 类型
TYPEID:自动增加只在dbo.EmpType
当我的empType更新typeid的价值,它需要获取存储在TYPEID dbo.Emp我用SP这是行不通的。
Create Procedure bridge_Type(
@EmpID INT,
@Name varchar(50),
@Mob2 numeric(10,0),
@Email varchar(50),
@Type varchar(50)
)
AS
DECLARE @TYPEID int
Set NOCOUNT OFF
BEGIN TRANSACTION
Insert into dbo.Emp VALUES (@EmpID, @Name, @Mob2, @Email, @TYPEID)
IF @@ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
INSERT INTO dbo.EmpType VALUES (@Type)
IF @@ERROR <> 0
BEGIN
ROLLBACK
RETURN
END
declare @id int
SET @id= @TYPEID;
Update Dbo.Emp
Set @TYPEID= (Select TypeID from dbo.EmpType
WHERE TypeID=@typeID)
COMMIT