db2 viper test windows
TRANSCRIPT
-
8/10/2019 DB2 Viper Test Windows
1/15
DB2 Express-C Viper test drive challenge
The DB2Viper data server provides many new capabilities including: flexible security
options, data storage optimiation, and improved support for storing, managing, and!uerying "#$ data% DB2 is designed to optimie access to "#$ and relational data and
these capabilities are available to &'', %()T, &*B*$, +ava, and - application
developers% DB2 Viper is now available .for evaluation purposes/ and this tutorial can beused to aid in understanding how to use "#$ and 01$ together to build the basis of a
flexible scheduling application%
TheDB2 Express-C Viper test drive challengeis a step by step tutorial to introduce thereader to the DB2 Viper data server on indows platforms using the "#$ storage and
searching .01$3"#$, "1uery/ capabilities available to support next generation
applications%
Introduction to DB2 Viper
DB2 Viper is the industry4s first hybrid data server for managing data from both
relational and pure "#$ formats% DB2 has been providing high performance data storageand access for relational data based on 01$ standards and data storage optimiations
such as data partitioning and advanced indexing and !uery optimiation techni!ues% (ow,
DB2 has introduced an optimied data storage engine for "#$ data alongside theexisting relational engine%
5pplication developers can now store "#$ data directly inside of a DB2 server and reapthe benefits of transactions, advanced data resiliency, secure access, and, of course, the
ability to search large amounts of "#$ data using "1uery%
"#$ data is often used for inter6application data exchange and document managementpurposes% The flexible and self6describing nature of "#$ data ma7es it ideal for many
application scenarios%
The ability to !uery "#$ data has been !uite limited% 8ecently, a new standards based
"#$ !uery language has been published% This !uery language is 7nown as "1uery
Version 9%%
"1uery Version 9% was released in (ovember 2; . http:33www%w
-
8/10/2019 DB2 Viper Test Windows
2/15
-
8/10/2019 DB2 Viper Test Windows
3/15
This tutorial will help familiarie you with DB24s new support for "#$ data% =ou will
perform the following tas7s:
9% &reate a DB2 Viper database .to support relational and "#$ data ob>ects/%2% &reate a DB2 table to store "#$ data%
-
8/10/2019 DB2 Viper Test Windows
4/15
12. $eave the DB2instance configuration as the default and clic7 Next% The
default DB2 instance name on indows is called DB2%
13. &lic7 (inish"to start the DB2 product installation, when you reach the
Start copying and !iles and create response !ile screen%
14. hen the installation is complete% 5 window with the message Setup is
complete will appear% &lic7 (inishto complete the installation procedure%15. 5 window entitled DB2 (irst Stepswill now appear% &lic7 )reate
pro!ile% =our web browser will open a page called DB2 (irst Steps% This tutorialcontains many useful lin7s to information on DB2, but it will not be used during
this tutorial% &lose your web browser and continue with this tutorial%
Getting Started with DB2 Viper
Step 1. Creating a DB2 Viper dataase
To get started, letFs create a new DB2 database% DB2 Viper supports pure "#$ data
storage and !uery for databases enabled for the C(?&*D) character set% ?n the following
steps we will create a C(?&*D) DB2 Viper database%
DB2 databases can be created using graphical tools%
DB2 Control Center ! C"E#$E D#$#B#SE
)reating a *TEST$ DB2 data%ase + DB2 )ontrol )enter ,
Start -. IB/ DB2 -. DB2 +de!ault, -. 0eneral Administration Tools -. )ontrol
)enter
ithin the DB2 &ontrol &enter application, choose the Basic 'iew% 8ight6clic7 on All
Data%asesand choose )reate Data%ase -. Standard% =ou will be presented with the
)reate Data%ase 1iard% Gill in the name as testand select Ena%le data%ase !or 3/L%
=our screen should appear li7e Gigure 9%
-
8/10/2019 DB2 Viper Test Windows
5/15
Gigure 9% &reate Database iard
&lic7 Nexttwice to get to the 4egionscreen% 0et the )ountry54egionas to the value
nited Statesand leave )ode setas the default value T(-6% &lic7 (inishto complete%
The TESTdatabase is now created and ready to store "#$ and relational data%
(*T): To create the same DB2 Viper database using DB2 &$:
db2 create db test using codeset utf- territor! us
Step 2. Creating a DB2 tale
DB2 columns can be defined using various data types including "#$% To store "#$data in DB2 simply specify the "#$ data type for one or more columns% DB2 tables may
contain a mixture of traditional and "#$ data types% DB2 uses optimal storagetechni!ues to store and maintain "#$ data in addition to providing powerful !uery
capabilities%
-
8/10/2019 DB2 Viper Test Windows
6/15
%&ption 1' DB2 Co((and )ine *rocessor ! C"E#$E $#B)E
?n this exercise, we will create a single table called "#$T%"T_S"&E'()ES, and it isused to trac7 basic contact information for a large number of people% The column called
S"&E'()Eis used to store each person4s schedule of activities as a single "#$document with one or more scheduled activities%
The data architect and application developer for this pro>ect decided to use "#$ to
enable a flexible infrastructure% 5ctivities are often integrated with other applications
.D5 devices and web collaboration tools/ and using a pure "#$ format for eachperson4s activities is ideal%
!"#$" $#&'" user1.c()t*ct_sc+edu,es-
id IN$ !I/#! " "N"!#$" #'W# # I"N$I$-$#!$ WI$ 1 IN!"/"N$ & 1)*me #!#!-20 N$ N;'',)*me #!#!-20 N$ N;''tit,e #!#!-30 N$ N;''/'
?
$isting 9% &reating the &*(T5&TH0&-)DC$)0 table
5s you can see in $isting 9, the N$#$_";'"table has a combination of
standard relational .?(T)I)8, &-585&T)8/ data types and a single "#$ column%
The Icolumn is also defined to be auto6generated column value and it has also been
defined as a primary 7ey for the table%
To use the DB2 )ommand Editor, launch the DB2 &ontrol &enter as described in step
9% 8ight clic7 on the TESTdatabase from the navigation tree and select 7ueryfrom thepop6up menu% The DB2 &ommand )ditor should now be open and establish a connection
to the TESTdatabase%
-
8/10/2019 DB2 Viper Test Windows
7/15
Gigure 2% DB2 &ommand )ditor
-
8/10/2019 DB2 Viper Test Windows
8/15
Gigure
-
8/10/2019 DB2 Viper Test Windows
9/15
Gigure @% &reate Table iard
*n step @ .Leys/ within the wiard, define the primary 7ey for 'by clic7ing AddPrimary% =ou can leave the primary 7ey name as the default or enter a name of your
choosing% &lic7 (inish%
Step +. Storing ,) data sing DB2 I/SE"$
The IN"!$statement can be used to store relational and "#$ data in a DB2 Viper
database% The "#$ data can be provided from any supported application programming
language or it could be provided directly within a DB2 &$ script% Gor this tutorial we
will use the DB2 )ommand Editorto store some initial schedules in the TESTdatabase%
e will now insert a record into the "#$T%"T_S"&E'()EStable for Grant Hutchisonand Gerald Leung%
Gor convenience the ?(0)8T statements have been provided in the following file:c:\temp\iperI)tr(\,isti)@s\,isti)@2.txt
-
8/10/2019 DB2 Viper Test Windows
10/15
IN"!$ IN$ user1.c()t*ct_sc+edu,es-)*me ,)*me tit,e
-
8/10/2019 DB2 Viper Test Windows
11/15
(ote that supplying the "#$ data inline .as shown in $isting 2/ re!uires you to invo7e
the 3/LPA4SEfunction to convert the document from a character data type to "#$%?n this case, the input document was !uite simple% ?f the document was large or complex,
it would be impractical to type the "#$ data into the ?(0)8T statement as shown% ?n
most cases, youFd write an application to insert the data using a host variable or aparameter mar7er% -owever, since this is an introductory tutorial, we wonFt be discussing
application development topics in detail% ?nstead, weFll discuss another option for
populating DB2 "#$ columns with data 66 using the DB2 ?#*8T facility%
Step 0. ering ,) data sing S) and ,3E"4
"1uery is a new language used for !uerying "#$ data% "1uery and 01$ can be used in
the same !uery to a database as seen in the next example% ?n the next !uery, we will use a
01$3"#$ statement% The part of the !uery outside of xmlexists+,is not case sensitivebecause that part is 01$% The part of the !uery inside of xmlexists+,is case sensitive
because it is "1uery, so this statement has "1uery embedded in an 01$ statement%
The following !uery retrieves all of the attendees of the ?DCIJ event:
"'"$ GH!/ user1.c()t*ct_sc+edu,esW"!" xm,exists-AsJsc+edu,eF*ctivitDF)*meKLI;LMA #INsc+edu,e # LsL?
$isting ust inserted% The xmlexistsfunction is using an "ath expression to determine which records should be returned%
The next statement has 01$ embedded in an "1uery statement% 5ny "1uery statemenmust start with the 7eyword 37E49J% 5s usual, the part inside s!l!uery./ is an 01$
statement, so that part is not case sensitive, but the part outside of s!l!uery./ is "1uery,
so that part is case sensitive% The following !uery tells us which activity Irant -utchisonis attending on 2A6;6M:
>;"! db2E):sO,OuerD-L"'"$ sc+edu,eH!/ user1.c()t*ct_sc+edu,esW"!" )*meKAr*)tA #N ,)*meKAutc+is()ALFsc+edu,eF*ctivitDJ*ctivitD*teFst*rt BK L2006E05E8LMJ*ctivitD*teFe)d CK L2006E05E08LM?
$isting @% 0earching for the schedule of Irant -utchisonJ
-
8/10/2019 DB2 Viper Test Windows
12/15
The !uery in $isting @ returns all the activities for Irant -utchison on #ay M th, 2A% ?n
this !uery we are using a combination of relational predicates and "1uery to limit theresult to a specific person and date%
4elational condition +predicate,W"!" )*me K Pr*)tQ #N ,)*me K Putc+is()Q
37uery conditionsc+edu,eF*ctivitDJ*ctivitD*teFst*rt BK L2006E05E08LMJ*ctivitD*teFe)d CK L2006E05E08LM
=ou will examine many more "1uery examples in 0tep A%
Step 5. 3sing I*&"$ to poplate DB2 tales with ,)
?f you already have your "#$ data in files, the DB2 ?#*8T command provides aconvenient method of populating your DB2 tables with relational and "#$ data% The
?#*8T command can use various import control file formats% ?n this example we will
use a delimited text file% The default delimiter for DB2 ?#*8T is the comma .N,4/, butthis can be changed% ?n this example we will use comma separated values and a special
reference techni!ue for the "#$ data for the schedulecolumn%
=ou can create the delimited 50&?? file using the text editor of your choice% )ach line in
your file represents a row of data to be imported into your table% ?f your line contains an
3/L Data Speci!ication +3DS," ?#*8T will read the "#$ data from the referenced
file% Gor example, the first line in $isting ; contains information for illiam 5dams,
including his name, title, and phone numbers%
William,Adams,Desktop Support,2200358048,5015651260,3200444463,
Betty,Adams,Technical Manager,2670248276,2534835325,2771104762,
. . .
$isting ;% 0ample delimited 50&?? file for input to DB2 ?#*8T
ith your "#$ files and delimited 50&?? files available, youFre now ready to use the
DB2 ?#*8T utility% The DB2 ?#*8T commands can be used to add more data to ourexisting "#$T%"T_S"&E'()EStable%
-
8/10/2019 DB2 Viper Test Windows
13/15
I/!$ H!/ Ac:\temp\iperI)tr(\sc+edu,es_imp(rt.de,A H "'>/' H!/ A:\temp\iperI)tr(\sc+edu,esA/IHI" & I"N$I$/IIN
IN"!$ IN$ user1.c()t*ct_sc+edu,es?
$isting A% ?mporting data into the OclientsO table
(ote: There are 9, "#$ documents in: c:\temp\iperI)tr(\sc+edu,es
e will proceed to ?#*8T all of these documents with a single DB2 command .as
shown in $isting A%
Execute the command in Listing : !rom the DB2 )ommand Editor;
The sc+edu,es_imp(rt.de,file contains references to the 9, data recordsincluding an "#$ files% %
Step 6. #dditional ,er Exa(ples
$et4s ta7e a !uic7 loo7 at some basic "1uery capabilities of DB2 Viper
$isting "1uery E 8etrieve all schedules
The "1uery in $isting can be used to retrieve all of the schedules stored in the"#$T%"T_S"&E'()EStable within the S"&E'()Ecolumn% The xmlcolumn+,function re!uires that the referenced table and column names is uppercase% The output of
the !uery in $isting would be e!uivalent to the following 01$ !uery:
SE)E"T schedule from (SE*,."#$T%"T_S"&E'()ES
e will now reduce the returned data set to only include the names of the cities ofscheduled activities for each person%
xOuerD db2E):xm,c(,um)-A;"!1.N$#$_";'".";'"A?
-
8/10/2019 DB2 Viper Test Windows
14/15
$isting M "1uery E 8etrieve all cities for each person
e will now limit the results to only activities in the city of
-
8/10/2019 DB2 Viper Test Windows
15/15
"'"$ ;N$-idH!/ user1.c()t*ct_sc+edu,esW"!" tit,eKAWeb eve,(perA #NN$ >/'">I$-AcFsc+edu,eF*ctivitDF*ctivitD*teJst*rt B curre)tEd*te-MJe)d C curre)tEd*te-MA #IN
sc+edu,e # LcL?
$isting 99% &reating a view that contains "#$ data
$isting 99 is using an "1uery expression embedded in an 01$ statement% Views over
"#$ data can simplify data access for all developers as the "1uery details can be stored
within the DB2 server and not necessarily exposed to each user or developer%
0)$)&T num5vailable G8*# user9%webDevTodayQ
$isting 92% -ow many eb Developers available todayR
Congratlations or DB2 Viper test drive tor is now co(plete 88
-opefully you now have a sense of the hybrid nature of data storage and access provided
with the new DB2 Viper data server% ?f you would li7e to learn more >oin the growing
DB2 Viper community on the web%
DB2 )xpress6& Viper Sone E Downloads, learning resources, and an active community
forum
http:33ww%ibm%com3db23express
DB2 Viper ?nformation &enter
http:33publib%boulder%ibm%com3infocenter3db2luw3vP
http://ww.ibm.com/db2/expresshttp://publib.boulder.ibm.com/infocenter/db2luw/v9http://ww.ibm.com/db2/expresshttp://publib.boulder.ibm.com/infocenter/db2luw/v9