17.10.2015 Views

Getting Started with IBM Data Studio for DB2

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

238 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>IBM</strong> <strong>Data</strong> <strong>Studio</strong> <strong>for</strong> <strong>DB2</strong><br />

8.1 Stored procedures: The big picture<br />

Stored procedures can help improve application per<strong>for</strong>mance and reduce database access<br />

traffic. All database access must go across the network, which, in some cases, can result<br />

in poor per<strong>for</strong>mance. Figure 8.1 illustrates the stored procedure data flow..<br />

Figure 8.1 Stored procedure data flow<br />

As shown in Figure 8.1, an application must initiate a separate communication <strong>with</strong> the<br />

<strong>DB2</strong> database server <strong>for</strong> each SQL statement. So, SQL #1, SQL #2, and SQL #3 require<br />

individual communication traffic.<br />

To improve application per<strong>for</strong>mance, you can create stored procedures that run on your<br />

database server. A client application can then simply call the stored procedures<br />

(MYPROC in Figure 8.1) to obtain results of all the SQL statements that are contained in<br />

the stored procedures. Because a stored procedure runs the SQL statements on the<br />

server <strong>for</strong> you, the overall per<strong>for</strong>mance is improved. In addition, stored procedures can<br />

help to centralize business logic. If you make changes to a stored procedure, the changes<br />

are immediately available to all client applications.<br />

Stored procedures are also very useful when deleting or updating large numbers of rows.<br />

You can specify a cursor in a stored procedure, and then loop through the result and<br />

delete or update rows. This reduces locking activity and is useful in an OLTP environment.<br />

8.2 Steps to create a stored procedure<br />

The recommended perspective <strong>for</strong> stored procedure development is the <strong>IBM</strong> SQL and<br />

Routine Development perspective. To switch to this perspective, select Window -> Open<br />

Perspective -> Other -> <strong>IBM</strong> SQL and Routine Development from the main menu.<br />

As discussed in Chapter 5, you must create a data development project to store routines.<br />

Each data development project is associated <strong>with</strong> a single database connection. In this<br />

chapter, we’ll be connecting to theGSDB sample database that has been used in previous

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!