Showing posts with label function. Show all posts
Showing posts with label function. Show all posts

Thursday, March 22, 2012

best practices for writing SQL server stored procedures

Dear All,

Please suggest some of the best practices for writing SQL server
stored procedures?
I'm writing a business function (stored procedure), which calls
many-stored procedure one after another.
I want this to be best optimized, so that speed can be very good.

Suggestion in this regard will be appreciated.

Thanks in advance,
T.S.NegiHere are some of the best practices that I use:
http://www.extremeexperts.com/SQL/A...tPractices.aspx

--
HTH,
Vinod Kumar
MCSE, DBA, MCAD, MCSD
http://www.extremeexperts.com

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp

"T.S.Negi" <tilak.negi@.mind-infotech.com> wrote in message
news:a1930058.0502132116.761a1b9a@.posting.google.c om...
> Dear All,
> Please suggest some of the best practices for writing SQL server
> stored procedures?
> I'm writing a business function (stored procedure), which calls
> many-stored procedure one after another.
> I want this to be best optimized, so that speed can be very good.
> Suggestion in this regard will be appreciated.
> Thanks in advance,
> T.S.Negi

Thursday, February 16, 2012

Behaviour of Merge Replication

I want to deepen the function of Merge Replication:
1) what's the main difference between a push subscription and a pull
subscription ?
2) if I have a subscriber node that for many time (4-5 months) is
disconnected from publisher, what will it do when it'll be re-connected
to the network ?
3) is there a method to force the re-synchronization of DB subscriber
in this case ?
4) instead if I have a failure of Publisher server, and I work only
with subscribers, what sould I do after the restart of Publisher to
load the changes made in subscribers DB ?
Hi Marco - answers inline:

> 1) what's the main difference between a push subscription and a pull
> subscription ?
Which box does the work. If I have the choice, I prefer to have the agents
centralised and use one set of alerts and notifications.
> 2) if I have a subscriber node that for many time (4-5 months) is
> disconnected from publisher, what will it do when it'll be re-connected
> to the network ?
It will error and require reinitialization.
> 3) is there a method to force the re-synchronization of DB subscriber
> in this case ?
The term we use is Reinitialization. sp_reinitmergesubscription and
sp_reinitmergepullsubscription can be used. Run the snapshot agent then the
merge agent.
> 4) instead if I have a failure of Publisher server, and I work only
> with subscribers, what sould I do after the restart of Publisher to
> load the changes made in subscribers DB ?
>
Restore an older version of the publisher's database and synchronize. This
is not foolproof (eg schema changes and download only articles will require
some thought) but it generally works.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com .
|||answers inline
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Marco" <peska78@.tin.it> wrote in message
news:1164723024.262636.185820@.h54g2000cwb.googlegr oups.com...
>I want to deepen the function of Merge Replication:
> 1) what's the main difference between a push subscription and a pull
> subscription ?
With a push the publisher initiates the sync, with a pull the subscriber
initiates it. Push is good for a small number of subscribers when you want
to centrally manage them. Pull is good for a large number of subscribers but
you don't have a central point of management.
> 2) if I have a subscriber node that for many time (4-5 months) is
> disconnected from publisher, what will it do when it'll be re-connected
> to the network ?
It will probably have expired so you will need to send a new snapshot down.
you can upload the subscriber changes before the snapshot is applied.
> 3) is there a method to force the re-synchronization of DB subscriber
> in this case ?
Its called a re-initialization. Expand your publication and right click on
your subscription and select reinitialize to reinitilize the problem
subscriber.
> 4) instead if I have a failure of Publisher server, and I work only
> with subscribers, what sould I do after the restart of Publisher to
> load the changes made in subscribers DB ?
>
Nothing. When the subscriber comes back on line it will synchronize changes
which have occurred with the subscribers. If the retention period has passed
most of your subscribers will probably have expired which means you will
have to reinitialize, run the snapshot agent and then run the merge agents.
|||Paul, Hilary
thanks for your answers.
|||Hi Josip
There is no hard rule defining small, or the cut off point going from push
to pull. I normally use pull for over 10 subscribers.
As you have some tables which are only one direction I would use
transactional replication. As you have some which are bi-directional I would
use merge for those.
For the merge publications use central publisher in your head office. For
the uni-directional publications it depends on the data flow, if they are
going to the central publisher make the branch offices the publishers, ie 14
publishers in the branch office going to the central publisher in the head
office. If they are going from the central publisher in the head office to
the subscribers branch office use the central publisher in the head office.
HTH
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"Josep" <jmartinez@.autec.es> wrote in message
news:e4BsFn5FHHA.1912@.TK2MSFTNGP03.phx.gbl...
> Hi Hilary,
> I new in replications and I've just realised that I need Merge replication
> (after reading the first chapter of your book). So I started looking for
> information about Merge. But still I've things unclear. For example, I
> don't know if I should use push or pull subscriber. When you say:
>
> what's a small number of subscribers? Because I've 15 machines to be
> replicated, where one is a dedicated server, the Central Server. Some
> tables must be replicated to everywhere (using the Central Server?) and
> some other tables just replicated to the Central Server (so a filter
> should be applied?). It's like a star topology.
> And this goes to another question. What's better, to have the publication
> in the Central Server and push/pull subscription to the other computers or
> generate a publication on each server and make the Central Server a
> subscriber of all?
> I think that the first option is the best, at least for the tables that
> must be replicated to everywhere, but I'm not sure for the tables that
> must be filtered.
>
> Thank you,
> Josep Martnez
>
> "Hilary Cotter" <hilary.cotter@.gmail.com> escribi en el mensaje
> news:eNEH1zvEHHA.4132@.TK2MSFTNGP04.phx.gbl...
>

Sunday, February 12, 2012

BEGIN TRAN . . . WITH MARK . . .

Hallo All,

Can somebody explain why the same function works different with MS SQL 2000 and MS SQL 2005?
On both systems 2000 and 2005 I have 2x databases named ACCT and PROD (actually only a test environment).
On both systems I try to execute the following statements:
BEGIN TRAN TRAN_01 WITH MARK 'My TRAN_01'
USE PROD
INSERT INTO [PROD].[dbo].[_PROT]([STR_COMMENT], [R_NUM_T1], [R_NUM_T2])
VALUES('PROT_COMMENT', 1004, 1004)
USE ACCT
INSERT INTO [ACCT].[dbo].[_PROT]([STR_COMMENT], [R_NUM_T1], [R_NUM_T2])
VALUES('PROT_COMMENT', 1004, 1004)
COMMIT TRAN TRAN_01
After executing the statements I start the following query:
SELECT * FROM [msdb].[dbo].[logmarkhistory]
On MS SQL 2000 I get as results:
PROD TRAN_01 My TRAN_01 SUPPORT\Administrator 3944000000107600001 2006-03-29 17:15:13.930
ACCT TRAN_01 My TRAN_01 SUPPORT\Administrator 8000000009200001 2006-03-29 17:15:13.930
Seems to be correct. I think it is the way it should work according to the documentation.

On MS SQL 2005 I only get the following results:
PROD TRAN_01 My TRAN_01 SU 29000000107800001 2006-03-29 17:31:32.283
There are no entries in the table for the ACCT database and the account / user_name is shown incorrectly.
It seems to be an ERROR in the processing of such marked transactions in MS SQL 2005.
See the Books Online Topic "Ensuring Recoverability of Related Databases". I believe that there is a change in SQL Server 2005.|||Hello ALL,
I have the solution now.
It have nothing to do with some changes in SQL Server 2005.
It seems just to be the following. I habe never made a backup
of the ACCT database in the past. After I executed the full
online backup of the ACCT database for the first time I get
exactly the same results as with MS SQL 2000.