解决方法
您可以使用远程端的sp_executesql:
DECLARE @ScopeIdentity (ID int); INSERT INTO @ScopeIdentity EXEC server.master..sp_executesql N' INSERT INTO database.schema.table (columns) VALUES (values); SELECT SCOPE_IDENTITY()'; SELECT * FROM @ScopeIdentity;
或者,您可以使用OPENQUERY:
SELECT * FROM OPENQUERY(server,' INSERT INTO database.schema.table (columns) VALUES (values); SELECT SCOPE_IDENTITY() AS ID');