Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
IBM DB2 9.7 Advanced Application Developer Cookbook

You're reading from  IBM DB2 9.7 Advanced Application Developer Cookbook

Product type Book
Published in Mar 2012
Publisher Packt
ISBN-13 9781849683968
Pages 442 pages
Edition 1st Edition
Languages
Toc

Table of Contents (15) Chapters close

IBM DB2 9.7 Advanced Application Developer Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
1. Application Development Enhancements in DB2 9.7 2. DB2 Application Techniques 3. General Application Design 4. Procedures, Functions, Triggers, and Modules 5. Designing Java Applications 6. DB2 9.7 Application Enablement 7. Advanced DB2 Application Features and Practices 8. Preparing and Monitoring Database Applications 9. Advanced Performance Tuning Tips

Changing column names online using the ALTER TABLE operation


To rename a column in earlier versions of DB2, we used to recreate the table with a new column name and then insert the data from the earlier table on to a newly created table. The catch here is that while renaming the table, the source table should not have any references such as views, indexes, MQTs, functions, triggers, and constraints. This makes an application developer depend on a database administrator while changing the database object, based on the business requirement. In DB2 9.7, renaming a column is made extremely easy with just a single command inside the application code.

Getting ready

You need to have the ALTER privilege on the table that needs to be altered.

How to do it...

You can rename an existing column in the table to a new name without losing the data, privileges, and LBAC policies.

The DB2 command syntax to rename the column is as follows:

ALTER TABLE <SCHEMAS>.<TABLENAME> RENAME COLUMN <COLUMN> TO <NEW COLUMN >

For example:

ALTER TABLE DBUSER.DEPARTMENT RENAME COLUMN LOC TO LOCATION

After renaming the column, the application can start accessing the table without a table REORG requirement.

How it works…

When an ALTER TABLE RENAME COLUMN command runs on the system, DB2 will rename the column in the table and invalidate the dependent objects (if any) such as views, functions, procedures, materialized query tables (MQT), and so on. Invalidated objects would get validated when the dependent objects are being accessed within the application or outside the application by a user. This automatic revalidation of invalid database objects depends on the value of the database configuration parameter, auto_reval.

See also

Refer to the Using the CREATE WITH ERROR support recipe for more details on automatic revalidation of invalid database objects, discussed in this chapter.

You have been reading a chapter from
IBM DB2 9.7 Advanced Application Developer Cookbook
Published in: Mar 2012 Publisher: Packt ISBN-13: 9781849683968
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}