Scope_Identity() - 输出参数与否? [英] Scope_Identity() - Output parameter or not?
本文介绍了Scope_Identity() - 输出参数与否?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Sql Server,Scope_Identity(),Ado.NET:
哪个更好?使用输出参数通过
ExecuteNonQuery()返回Scope_Identity,或者将选择Scope_Identity()添加到
过程或临时SQL的末尾并使用ExecuteScalar()?
谢谢。
解决方案
标准方法是运行一批
INSERT ...;在单个ExecuteScalar调用中选择SCOPE_IDENTITY()...
。
-
Eliyahu Goldin,
软件开发人员&顾问
Microsoft MVP [ASP.NET]
http: //msmvps.com/blogs/egoldin
" Mike" < bl *** @ blank.blankwrote in message
news:uX ************** @ TK2MSFTNGP06.phx.gbl ...
Sql Server,Scope_Identity(),Ado.NET:
哪个更好?使用输出参数返回Scope_Identity
到
ExecuteNonQuery(),或添加Select Scope_Identity()到
程序或临时SQL的结尾并使用ExecuteScalar()?
谢谢。
太棒了!这就是我的工作,但我已经在这里和那里看到了使用输出
参数的例子,并想知道为什么。
谢谢
Mike
" Eliyahu Goldin" < RE ************************** @ mMvVpPsS.org写在
消息新闻:e%*** ************* @ TK2MSFTNGP03.phx.gbl ...
标准方法是运行批处理
INSERT ...;在单个ExecuteScalar调用中选择SCOPE_IDENTITY()...
。
-
Eliyahu Goldin,
软件开发人员&顾问
Microsoft MVP [ASP.NET]
http: //msmvps.com/blogs/egoldin
" Mike" < bl *** @ blank.blankwrote in message
news:uX ************** @ TK2MSFTNGP06.phx.gbl ...
> Sql Server,Scope_Identity(),Ado.NET:
哪个更好?使用输出参数返回Scope_Identity
到
> ExecuteNonQuery(),或添加Select Scope_Identity ()结束
程序或临时SQL并使用ExecuteScalar()?
谢谢。
Mike,
我相信使用输出参数更有效。
如果你选择scope_identity()技术你返回一个
整行数据作为DataSet,DataTable,DataReader ..还有
与它相关的开销(更多网络流量,更大对象
实例化)
输出参数肯定更好。
Vince
5月31日下午4:56,Mike < b ... @ blank.blankwrote:
太棒了!这就是我的工作,但我已经在这里和那里看到了使用输出
参数的例子,并想知道为什么。
谢谢
Mike
" Eliyahu Goldin" < REMOVEALLCAPITALSeEgGoldD ... @ mMvVpPsS.org写在
messagenews:e%**************** @ TK2MSFTNGP03.phx.gb l ...
标准方法是运行批处理
INSERT ...; SELECT SCOPE_IDENTITY()...
在单个ExecuteScalar调用中。
-
Eliyahu Goldin,
软件开发人员&顾问
Microsoft MVP [ASP.NET]
http: //msmvps.com/blogs/egoldin
" Mike" < b ... @ blank.blankwrote in message
news:uX ************** @ TK2MSFTNGP06.phx.gbl ...
Sql Server,Scope_Identity(),Ado.NET:
哪个更好?使用输出参数返回Scope_Identity
到
ExecuteNonQuery(),或添加Select Scope_Identity()到
程序或临时SQL结束并使用ExecuteScalar()?
Thanks.-隐藏引用的文字 -
- 显示引用的文字 -
Sql Server, Scope_Identity(), Ado.NET:
Which is better? Using an output parameter to return Scope_Identity through
ExecuteNonQuery(), or adding Select Scope_Identity() to the end of the
procedure or ad hoc SQL and using ExecuteScalar()?
Thanks.
解决方案
The standard way is to run a batch
INSERT...;SELECT SCOPE_IDENTITY()...
in a single ExecuteScalar call.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mike" <bl***@blank.blankwrote in message
news:uX**************@TK2MSFTNGP06.phx.gbl...Sql Server, Scope_Identity(), Ado.NET:
Which is better? Using an output parameter to return Scope_Identitythrough
ExecuteNonQuery(), or adding Select Scope_Identity() to the end of the
procedure or ad hoc SQL and using ExecuteScalar()?
Thanks.
Great! That''s what I do, but I''ve seen examples here and there using output
parameters and wondered why.
Thanks
Mike
"Eliyahu Goldin" <RE**************************@mMvVpPsS.orgwrote in
message news:e%****************@TK2MSFTNGP03.phx.gbl...The standard way is to run a batch
INSERT...;SELECT SCOPE_IDENTITY()...
in a single ExecuteScalar call.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mike" <bl***@blank.blankwrote in message
news:uX**************@TK2MSFTNGP06.phx.gbl...>Sql Server, Scope_Identity(), Ado.NET:
Which is better? Using an output parameter to return Scope_Identitythrough
>ExecuteNonQuery(), or adding Select Scope_Identity() to the end of the
procedure or ad hoc SQL and using ExecuteScalar()?
Thanks.
Mike,
I believe using a output parameter is more efficient.
If you do the select scope_identity() technique you are returning an
entire row of data as a DataSet, DataTable, DataReader.. There is
still overhead associated with it (more network traffic, bigger object
to instantiate)
An output parameter is certainly better.
Vince
On May 31, 4:56 pm, "Mike" <b...@blank.blankwrote:Great! That''s what I do, but I''ve seen examples here and there using output
parameters and wondered why.
Thanks
Mike
"Eliyahu Goldin" <REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote in
messagenews:e%****************@TK2MSFTNGP03.phx.gb l...
The standard way is to run a batch
INSERT...;SELECT SCOPE_IDENTITY()...
in a single ExecuteScalar call.
--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
"Mike" <b...@blank.blankwrote in message
news:uX**************@TK2MSFTNGP06.phx.gbl...Sql Server, Scope_Identity(), Ado.NET:
Which is better? Using an output parameter to return Scope_Identitythrough
ExecuteNonQuery(), or adding Select Scope_Identity() to the end of the
procedure or ad hoc SQL and using ExecuteScalar()?
Thanks.- Hide quoted text -
- Show quoted text -
这篇关于Scope_Identity() - 输出参数与否?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文