Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Questions about generated stored procedures by VS 2005 (Ta..

 
   Database Help (Home) -> Programming RSS
Next:  BIDS - Cube calculation designer: Unexpected erro..  
Author Message
Steven Spits

External


Since: Sep 21, 2006
Posts: 4



(Msg. 1) Posted: Thu Sep 21, 2006 8:51 pm
Post subject: Questions about generated stored procedures by VS 2005 (TableAdapter).
Archived from groups: microsoft>public>dotnet>framework>adonet, others (more info?)

Hi,

When I let a TableAdapter generate stored procedure for "SELECT * FROM
Supplier WHERE SupplierID = @SupplierID", it generates (some parts removed):

Select:
SET NOCOUNT ON;
SELECT * FROM Supplier WHERE SupplierID = @SupplierID

Update:
SET NOCOUNT OFF;
UPDATE [Supplier] SET <...> WHERE <...>;
SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);

Insert:
SET NOCOUNT OFF;
INSERT INTO [Supplier] VALUES <...>;
SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);

Delete:
SET NOCOUNT OFF;
DELETE FROM [Supplier] WHERE <...>;

My questions:

(1) Why does Visual Studio generate a SELECT after the INSERT & UPDATE
statements?

(2) Why is NOCOUNT set to ON in the select?

Kind regards,

Steven

- - -

 >> Stay informed about: Questions about generated stored procedures by VS 2005 (Ta.. 
Back to top
Login to vote
David Browne

External


Since: Sep 18, 2003
Posts: 126



(Msg. 2) Posted: Thu Sep 21, 2006 8:51 pm
Post subject: Re: Questions about generated stored procedures by VS 2005 (TableAdapter). [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"Steven Spits" wrote in message

> Hi,
>
> When I let a TableAdapter generate stored procedure for "SELECT * FROM
> Supplier WHERE SupplierID = @SupplierID", it generates (some parts
> removed):
>
> Select:
> SET NOCOUNT ON;
> SELECT * FROM Supplier WHERE SupplierID = @SupplierID
>
> Update:
> SET NOCOUNT OFF;
> UPDATE [Supplier] SET <...> WHERE <...>;
> SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);
>
> Insert:
> SET NOCOUNT OFF;
> INSERT INTO [Supplier] VALUES <...>;
> SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);
>
> Delete:
> SET NOCOUNT OFF;
> DELETE FROM [Supplier] WHERE <...>;
>
> My questions:
>
> (1) Why does Visual Studio generate a SELECT after the INSERT & UPDATE
> statements?

To get the results of any identity columns, computed columns, defaults or
triggers.

>
> (2) Why is NOCOUNT set to ON in the select?

Because setting NOCOUNT ON is a general best-practice. It's only set OFF
for the DML to inform of the number of rows affected.

David

 >> Stay informed about: Questions about generated stored procedures by VS 2005 (Ta.. 
Back to top
Login to vote
Arnie Rowland

External


Since: Jul 21, 2006
Posts: 86



(Msg. 3) Posted: Thu Sep 21, 2006 8:51 pm
Post subject: Re: Questions about generated stored procedures by VS 2005 (TableAdapter). [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

First off, recognize that Visual Studio, normally, IS NOT creating Stored
Procedures. It is creating 'inline' SQL code that will be submitted for the
appropriate datadapapter command. It will often be more efficient to create
stored procedures and use them instead of inline code.

Your questions:

1. The SELECT after a UPDATE or INSERT or DELETE is used to refresh your
dataset. Other users may have been making changes to the data included in
your dataset.

2. SET NOCOUNT ON curtails a unnecessary (in most situations) roundtrip
between the client and the server to send back the number of rows affected
by the command.

--
Arnie Rowland, Ph.D.
Westwood Consulting, Inc

Most good judgment comes from experience.
Most experience comes from bad judgment.
- Anonymous


"Steven Spits" wrote in message

> Hi,
>
> When I let a TableAdapter generate stored procedure for "SELECT * FROM
> Supplier WHERE SupplierID = @SupplierID", it generates (some parts
> removed):
>
> Select:
> SET NOCOUNT ON;
> SELECT * FROM Supplier WHERE SupplierID = @SupplierID
>
> Update:
> SET NOCOUNT OFF;
> UPDATE [Supplier] SET <...> WHERE <...>;
> SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);
>
> Insert:
> SET NOCOUNT OFF;
> INSERT INTO [Supplier] VALUES <...>;
> SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);
>
> Delete:
> SET NOCOUNT OFF;
> DELETE FROM [Supplier] WHERE <...>;
>
> My questions:
>
> (1) Why does Visual Studio generate a SELECT after the INSERT & UPDATE
> statements?
>
> (2) Why is NOCOUNT set to ON in the select?
>
> Kind regards,
>
> Steven
>
> - - -
>
>
>
 >> Stay informed about: Questions about generated stored procedures by VS 2005 (Ta.. 
Back to top
Login to vote
Steven Spits

External


Since: Sep 21, 2006
Posts: 4



(Msg. 4) Posted: Thu Sep 21, 2006 9:54 pm
Post subject: Re: Questions about generated stored procedures by VS 2005 (TableAdapter). [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

"David Browne" wrote:

>> (1) Why does Visual Studio generate a SELECT after the INSERT & UPDATE
>> statements?

> To get the results of any identity columns, computed columns, defaults or
> triggers.

And in my particular case, what happens with that data? Will the
TableAdapter update the row in the DataSet with the newly read data?

>> (2) Why is NOCOUNT set to ON in the select?

> Because setting NOCOUNT ON is a general best-practice. It's only set OFF
> for the DML to inform of the number of rows affected.

So it's only needed for statements that need to check for concurrency
violation, like DELETE, INSERT & UPDATE?

Steven

- - -
 >> Stay informed about: Questions about generated stored procedures by VS 2005 (Ta.. 
Back to top
Login to vote
Ivan Arjentinski

External


Since: Sep 24, 2006
Posts: 1



(Msg. 5) Posted: Sun Sep 24, 2006 7:47 pm
Post subject: Re: Questions about generated stored procedures by VS 2005 (TableAdapter). [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

> Update:
> SET NOCOUNT OFF;
> UPDATE [Supplier] SET <...> WHERE <...>;
> SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);
>
> Insert:
> SET NOCOUNT OFF;
> INSERT INTO [Supplier] VALUES <...>;
> SELECT SupplierID, <...> FROM Supplier WHERE (SupplierID = @SupplierID);
>
This behaviour of VS could be turned off. There was a checkbox somewhere in
the wizard which removes the additional SELECTs if you don't need them
 >> Stay informed about: Questions about generated stored procedures by VS 2005 (Ta.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Importing Stored Procedures using SQLSERVER 2005? - I have just installed SQL SERVER 2005 and I cannot find the import options for SQL SERVER Stored Procedures. There is a table import option. I saw something about writing a script to import stored procedures. Does anyone have any ideas about this?

How to copy stored procedures (in SQL 2005)? - I am trying to move sp from SQL2000 to SQL2005. I guess I have to go to do this procedure (below).. "Right click on the database in the object explorer, go Tasks->Generate Scripts. Set Script Object-Level Permission to True, click Next, check o...

using IronPython stored procedures in SQL Server 2005? - Has anybody had luck getting IronPython assemblies to work in SQL Server 2005? I can't seem to find a definitive answer on whether or not this is possible. vic

SQL Server 2005 Stored Procedures and Cursors - I have written a stored procedure that a) defines a cursor b) Loops through the cursor until it reaches the end of table. I doesn't do anything in between. This procedure takes 40 secs to complete and used 100% of cpu for that period. When execute..

Forward engineer stored procedures from vss SQL 2005 - Hi, I'm looking for a way to forward engineer all the stored procedures from vss to a SQL Server 2005 database. getting sps in is not a problem but if i want to say, create all the procs from vss is there a tool to do that assuming the .sql files are in....
   Database Help (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]