------最佳解决方案-------------------- 用Scope_Identity()实现
Create database A
Go
Use A
GO
Create table T1(Id int identity(1,1),name varchar(10),Id2 int)
Go
Create database B
Go
Use B
Create table T2(Id int identity(1,1),name varchar(10))
Go
Use B
Go
Declare @Id int
Insert into T2
Select '张三'
Set @Id = Scope_identity()
Insert into A.dbo.T1
Select '1班',@Id
Select * from A.dbo.T1
Select * from B.dbo.T2
Go
Use Master
Go
Drop database A
Drop database B ------其他解决方案-------------------- null ------其他解决方案--------------------