0% found this document useful (0 votes)
27 views

Stored Procedures and Remote Procedures Call (RPC)

The document discusses stored procedures and remote procedure calls (RPCs). It provides information on: 1) Stored procedures, which are named collections of SQL statements and logic stored on a database server. They are used to enforce business rules, perform administration tasks, and extend database functions. 2) Remote procedure calls, which allow calling procedures located on remote systems. RPCs hide network communication details and allow distributed applications. 3) The process for executing stored procedures and making RPCs involves parameter passing, marshalling, transport, and return results. Standards vary across database vendors for stored procedures.

Uploaded by

Arnel Decio
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Stored Procedures and Remote Procedures Call (RPC)

The document discusses stored procedures and remote procedure calls (RPCs). It provides information on: 1) Stored procedures, which are named collections of SQL statements and logic stored on a database server. They are used to enforce business rules, perform administration tasks, and extend database functions. 2) Remote procedure calls, which allow calling procedures located on remote systems. RPCs hide network communication details and allow distributed applications. 3) The process for executing stored procedures and making RPCs involves parameter passing, marshalling, transport, and return results. Standards vary across database vendors for stored procedures.

Uploaded by

Arnel Decio
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

ored Procedures and Remote Procedur

Call (RPC)
Stored
Procedures
Stored Procedures

Stored Procedure is a named collection of SQL statements and procedural logic


that is compiled, verified and stored in the server database.

• Sybase pioneered this concept of stored procedure in 1986 to improve the


performance of SQL on networks.

• The major database vendors are now offering an RPC-like mechanism for
executing functions that are stored in their databases. This mechanism is
sometimes referred to as “TP-Lite” or “stored procedure”.

• A stored procedure is typically treated like any other database object and
registered in the SQL catalog. The access to the stored procedure is controlled
through the server’s security mechanisms.
Stored Procedures

They are:
1. Used to enforce business rules and data integrity
2. Perform system maintenance and administration functions
3. To extend the database server’s functions
4. Used to create the server side of application logic.
5. It is also well suited for creating performance-critical applications
known as Online Transaction Processing OLTP
Stored Procedures

Major Drawbacks of Stored Procedure:


1. They provide less ad hoc flexibility than remote dynamic SQL.
2. They may perform very poorly if their plans are not refreshed/ rebound to take
advantage of the optimize statistics.
3. They are totally non-standard. Results in number of problems, no two-vendor
implementations are alike.
4. There is no standard way to pass or describe the parameters.
5. The language for describing the stored procedure is not portable across vendor
platform.
6. There is no transactional synchronization- i.e., two-phase commit between
stored procedures; where each stored procedure is a separate transaction.
Stored Procedures

Typically these applications can

1. Receive a fixed set of inputs from remote clients


2. Perform multiple precompiled SQL commands against a local database
3. Commit the work
4. Return a fixed set of results.
5. Stored Procedures are database-centric, RPC-like SQL entity that is persistent,
shared and has a name,
6. It reduces the network traffic and improves the response time.
7. Provide better site autonomy because the remote modification of tables can only
occur through locally executing programs.
8. Any changes are made to the tables need not be recompiled in all applications in
the remote machines.
9. They provide better distribution of intelligence than static or dynamic SQL.
10.It provide service-oriented interface that is well suited for OLTP applications.
Stored Procedures

Benefits of using a stored procedure


• It can be easily modified: We can easily modify the code inside the stored procedure without the need to
restart or deploying the application. For example, If the T-SQL queries are written in the application and if
we need to change the logic, we must change the code in the application and re-deploy it. SQL Server
Stored procedures eliminate such challenges by storing the code in the database. so, when we want to
change the logic inside the procedure we can just do it by simple ALTER PROCEDURE statement.

• Reduced network traffic: When we use stored procedures instead of writing T-SQL queries at the
application level, only the procedure name is passed over the network instead of the whole T-SQL code.

• Reusable: Stored procedures can be executed by multiple users or multiple client applications without the
need of writing the code again.

• Security: Stored procedures reduce the threat by eliminating direct access to the tables. we can also
encrypt the stored procedures while creating them so that source code inside the stored procedure is not
visible. Use third-party tools like ApexSQL Decrypt to decrypt the encrypted stored procedures.

• Performance: The SQL Server stored procedure when executed for the first time creates a plan and stores
it in the buffer pool so that the plan can be reused when it executes next time.
Stored Procedures

Stored Procedure Syntax

Execute a Stored Procedure

Example: Database
Below is a selection from the "Customers" table in the Northwind sample database:
CustomerID CustomerName ContactName Address City PostalCode Country

1 Alfreds Futterkiste Maria Anders Obere Str. 57 Berlin 12209 Germany

2 Ana Trujillo Ana Trujillo Avda. de la México D.F. 05021 Mexico


Emparedados y Constitución 2222
helados

3 Antonio Moreno Antonio Moreno Mataderos 2312 México D.F. 05023 Mexico
Taquería

4 Around the Horn Thomas Hardy 120 Hanover Sq. London WA1 1DP UK

5 Berglunds snabbköp Christina Berglund Berguvsvägen 8 Luleå S-958 22 Sweden


Remote
Procedures
Call (RPC)
Remote Procedures Call (RPC)

Remote Procedure Call (RPC) is a powerful technique for constructing distributed, client-


server based applications. It is based on extending the conventional local procedure calling so
that the called procedure need not to exist in the same address space as the calling
procedure. The two processes may be on the same system, or they may be on different systems
with a network connection. 
When making a Remote Procedure Call: 
Remote Procedures Call (RPC)

1. The calling environment is suspended, procedure parameters are


transferred across the network to the environment where the procedure is to
execute, and the procedure is executed there. 

2. When the procedure finishes and produces its results, its results are
transferred back to the calling environment, where execution resumes as if
returning from a regular procedure call. 
Remote Procedures Call (RPC)

NOTE: RPC is especially well suited for client-server (e.g. query-response) interaction in which the flow
of control alternates between the caller and callee. Conceptually, the client and server do not both execute
at the same time. Instead, the thread of execution jumps from the caller to the callee and then back again. 
Working of RPC 
Remote Procedures Call (RPC)

The following steps take place during a RPC : 


1.A client invokes a client stub procedure, passing parameters in the usual way. The client stub resides within
the client’s own address space. 
 
2.The client stub marshalls(pack) the parameters into a message. Marshalling includes converting the
representation of the parameters into a standard format, and copying each parameter into the message. 
 
3.The client stub passes the message to the transport layer, which sends it to the remote server machine. 
 
4.On the server, the transport layer passes the message to a server stub, which demarshalls(unpack) the
parameters and calls the desired server routine using the regular procedure call mechanism. 
 
5.When the server procedure completes, it returns to the server stub (e.g., via a normal procedure call
return), which marshalls the return values into a message. The server stub then hands the message to the
transport layer. 
 
6.The transport layer sends the result message back to the client transport layer, which hands the message back
to the client stub. 
 
Remote Procedures Call (RPC)

ADVANTAGES :
1. RPC provides ABSTRACTION i.e message-passing nature of network
communication is hidden from the user. 
 
2.RPC often omits many of the protocol layers to improve performance. Even a
small performance improvement is important because a program may invoke
RPCs often. 
 
3.RPC enables the usage of the applications in the distributed environment, not
only in the local environment. 
 
4.With RPC code re-writing / re-developing effort is minimized. 
 
5.Process-oriented and thread oriented models supported by RPC. 
Remote Procedures Call (RPC)

RPC ISSUES :
Issues that must be addressed:
1. RPC Runtime: 
RPC run-time system is a library of routines and a set of services that handle the network
communications that underlie the RPC mechanism. In the course of an RPC call, client-side and
server-side run-time systems’ code handle binding, establish communications over an appropriate
protocol, pass call data between the client and server, and handle communications errors. 

2. Stub: 
The function of the stub is to provide transparency to the programmer-written application code. 
•On the client side, the stub handles the interface between the client’s local procedure call and the run-
time system, marshaling and unmarshaling data, invoking the RPC run-time protocol, and if requested,
carrying out some of the binding steps. 
•On the server side, the stub provides a similar interface between the run-time system and the local
manager procedures that are executed by the server. 
Remote Procedures Call (RPC)

3. Binding: How does the client know who to call, and where the service resides? 
The most flexible solution is to use dynamic binding and find the server at run time when
the RPC is first made. The first time the client stub is invoked, it contacts a name server to
determine the transport address at which the server resides. 

4. The call semantics associated with RPC : It is mainly classified into following choices-
• Retry request message –Whether to retry sending a request message when a server has
failed or the receiver didnt receive the message.

• Duplicate filtering –Remove the duplicate server requests.

• Retransmission of results –To resend lost messages without re-executing the


operations at the server side. 
References
Akanksha_Rai. (2021, July 07). geeksforgeeks.org. Retrieved from GeeksforGeeks:
https://www.geeksforgeeks.org/remote-procedure-call-rpc-in-operating-system/

You might also like