Skip to Main Content
MySQL Stored Procedure Programming
book

MySQL Stored Procedure Programming

by Guy Harrison, Steven Feuerstein
March 2006
Intermediate to advanced content levelIntermediate to advanced
640 pages
17h 8m
English
O'Reilly Media, Inc.
Content preview from MySQL Stored Procedure Programming

Name

STYL-05: Use vertical code alignment to emphasize vertical relationships

Synopsis

A common code formatting technique is vertical alignment. Here is an example in a SQL WHERE clause:

    WHERE  COM.company_id      = SAL.company_id
       AND COM.company_type_cd = TYP.company_type_cd
       AND TYP.company_type_cd = CFG.company_type_cd
       AND COM.region_cd       = REG.region_cd
       AND REG.status          = RST.status;

You should use vertical alignment only when the elements that are lined up vertically have a relationship with each other that you want to express. In the WHERE clause shown here, however, there is no relationship between the right sides of the various expressions. The relationship is between the left and right sides of each individual expression. This is, therefore, a misuse of vertical alignment.

Example

Developers often (and justifiably) use vertical alignment with program parameter lists, as in:

    CREATE PROCEDURE maximize_profits
     (
       IN     advertising_budget    NUMERIC(12,2),
       INOUT  bribery_budget        NUMERIC(12,2),
       IN     merge_and_purge_on    DATE ,
       OUT    obscene_bonus         NUMERIC(12,2))

Vertical alignment allows you to easily see the different parameter modes and data types.

Vertical alignment is also handy when declaring many variables, as in:

 CREATE PROCEDURE genAPI( ) DETERMINISTIC BEGIN DECLARE c_table CHAR(5) DEFAULT 'TABLE'; DECLARE c_column CHAR(6) DEFAULT 'COLUMN'; DECLARE c_genpky CHAR(6) DEFAULT 'GENPKY'; DECLARE c_genpkyonly CHAR(10) DEFAULT 'GENPKYONLY'; DECLARE c_sequence CHAR(7) DEFAULT 'SEQNAME'; DECLARE c_pkygenproc ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

MySQL Concurrency: Locking and Transactions for MySQL Developers and DBAs

MySQL Concurrency: Locking and Transactions for MySQL Developers and DBAs

Jesper Wisborg Krogh
MySQL 8 Administrator???s Guide

MySQL 8 Administrator???s Guide

Chintan Mehta, Hetal Oza, Subhash Shah, Ravi Shah
MySQL Cookbook, 4th Edition

MySQL Cookbook, 4th Edition

Sveta Smirnova, Alkin Tezuysal
Learning MySQL, 2nd Edition

Learning MySQL, 2nd Edition

Vinicius M. Grippa, Sergey Kuzmichev

Publisher Resources

ISBN: 0596100892Supplemental ContentErrata Page