Ways to Create a Database An overview of the various ways to create a database. (Click for Flash demo) How to Execute a Simple Query A query of the SAMPLE database using the Command Editor. (Click for Flash demo) |
With the release of DB2 v9, aka Viper, IBM has debuted what could be considered the world's first hybrid XML and relational database. In other words, if there is such a thing as native XML management, Viper has it. But it also has a lot more.
As a regular visitor to this site, you've no doubt read about a lot of Viper's new XML capabilities, especially its new query language targeting XML data, XQuery. Here, you'll get a quick rundown of some of that power by creating an XML-enabled database and importing a very large raw data set. Then you'll go beyond that with a look at some of its other new features.
Hands-on Look at Viper
But first, take a look at the database itself. IBM has made the download available. If you're not quite ready to download it, here are some demos to let you play around with the look and feel of Viper.
Quick Tip: to create the sample database you see in these walkthroughs, run the db2sampl utility (see Figure 1).
![]() Figure 1. DB2Sampl.exe |
Creating Your Shakespearean Database
You probably already known how to create a database, but this walkthrough will go over creation of a simple demo table, including a field with type "xml", which is new to Viper. Once the table is created, you have a couple of ways to import data into the field, including using the "Import..." option from the table context menu. This walkthrough will cover using the "import" command in the command editor.
PLAYID: INTEGER (4), not nullable, Identity: initial value 1
PLAYNAME: VARCHAR (50), not nullable
PLAYTEXT: XML, nullable
![]() Figure 2. New Table in Compressed Format |
CONNECT TO SHAKES;
CREATE TABLE VIPER1.PLAYS
( PLAYID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START
WITH 1, INCREMENT BY 1, NO CACHE ) ,
PLAYNAME VARCHAR (50) NOT NULL ,
PLAYTEXT XML ,
CONSTRAINT CC1145679938359 PRIMARY KEY ( PLAYID) ) COMPRESS YES ;
CONNECT RESET;
All's Well That End's Well,<XDS FIL='all_well.xml' />
Love's Labor's Lost,<XDS FIL='lll.xml' />
Richard III,<XDS FIL='rich_iii.xml' />
Save the file to your root and name it "C:\BILLDEMO\plays.del".
REGISTER XSROBJECT 'play.dtd'
FROM 'C:\BILLDEMO\play.dtd'
AS VIPER1.SHAKESDTD DTD ;
IMPORT FROM 'C:\BILLDEMO\plays.del' OF DEL
XML FROM 'C:\BILLDEMO'
MODIFIED BY IDENTITYMISSING
INSERT INTO VIPER1.PLAYS
Self-Managing Memory
As virtualization picks up steam, enterprises are taking notice of products that can take advantage of a distributed architecture. DB2 v8.2 began stepping up with its Automatic Store Manager. Essentially, you could point the database to a set of drives and say "use that." DB2 would obediently distribute storage across what resources were available at the time.
With Viper, this is turned on by default. But now you have the next step: self-managing memory. Once you assign memory resources to your database, Viper has the intelligence to even the load. For more information, check out the IBM's InfoCenter on Memory Management.
![]() Figure 3. Specifying Storage in a New Database |
Label Based Security
Also new in Viper: Label Based Access Control (LBAC). Previous versions of DB2 relied on row-level security, already an advanced feature for some databases. Viper amps it up a notch by adding column-level security, as well. Here's how it works. You can define a label for a particular piece of data - as granular as a single value. Then assign permissions to that label to restrict access to it. This way, you can grant access down to specific data points.
Data Compression
Since V8, DB2 could compress data through techniques such as Value Compression for NULLs and zero-length values, and Compress System Default for default values. But alongside its XML functionality, Viper introduces a new data compression technique that works by suppressing repeat values.
This works primarily on relational data. For example, if you're creating a database of marsupials, you might have a lot of repeat data. There exists 93 species of opossum, 20 in the Genus Monodelphis alone, including the Southern Red-sided Opossum (Monodelphis sorex), the Southern Three-striped Opossum (Monodelphis theresa), and the Red Three-striped Opossum (Monodelphis umbristriata). To store this data more efficiently, leave the option "Store table in a compressed format" unchecked (Step 9 in the above walkthrough). Assuming you have Genus and Species broken out into separate fields, DB2 will be able to suppress the repeat values in the Genus field. If you compare it to an uncompressed database, you should see a marked difference.
Where to Go from Here
What you've seen here is a basic overview of DB2 Viper. In the coming weeks, you'll read more about the new features, including the DB2 Viper Workbench. In the meantime, download DB2 Viper now and start playing around with it.
Also, check out the following resources to learn more about Viper's XML capabilities, including XQuery code.