DB2 11.1 for LUW: SQL Basic Training for Application Developers
()
About this ebook
This book will teach you the basic information and skills you need to develop applications with DB2 SQL on IBM distributed computers running Linux, UNIX or Windows. The instruction, examples and sample programs in this book are a fast track to becoming productive as quickly as possible using SQL with the Java and c# .NET programming languages. The content is easy to read and digest, well organized and focused on honing real job skills.
Robert Wingate
Robert Wingate is a computer services professional with over 30 years of IBM mainframe and distributed programming experience. He holds several IBM certifications, including IBM Certified Application Developer - DB2 11 for z/OS, and IBM Certified Database Administrator for LUW. He lives in Fort Worth, Texas.
Read more from Robert Wingate
DB2 11 for z/OS: SQL Basic Training for Application Developers Rating: 4 out of 5 stars4/5Interview Questions for IBM Mainframe Developers Rating: 1 out of 5 stars1/5IMS-DB Basic Training For Application Developers Rating: 0 out of 5 stars0 ratingsCOBOL Basic Training Using VSAM, IMS and DB2 Rating: 5 out of 5 stars5/5MVS JCL Utilities Quick Reference, Third Edition Rating: 5 out of 5 stars5/5COBOL Language Fundamentals Quick Start Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals with VSAM Quick Start Rating: 0 out of 5 stars0 ratingsCOBOL Language Fundamentals with DB2 Quick Start Rating: 0 out of 5 stars0 ratingsDB2 11 for z/OS: Basic Training for Application Developers Rating: 5 out of 5 stars5/5DB2 Exam C2090-313 Practice Questions Rating: 0 out of 5 stars0 ratingsDB2 11 for z/OS: Intermediate Training for Application Developers Rating: 0 out of 5 stars0 ratingsInterview Questions for DB2 z/OS Application Developers Rating: 0 out of 5 stars0 ratingsPLI Basic Training Using VSAM, IMS and DB2 Rating: 1 out of 5 stars1/5DB2 Exam C2090-313 Preparation Guide Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-320 Preparation Guide Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-616 Practice Questions Rating: 5 out of 5 stars5/5DB2 11.1 for LUW: Basic Training for Application Developers Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-320 Practice Questions Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-615 Practice Questions Rating: 5 out of 5 stars5/5
Related to DB2 11.1 for LUW
Related ebooks
DB2 11.1 for LUW: Basic Training for Application Developers Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-615 Practice Questions Rating: 5 out of 5 stars5/5Database Design and SQL for DB2 Rating: 5 out of 5 stars5/5DB2 Exam C2090-320 Practice Questions Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-313 Practice Questions Rating: 0 out of 5 stars0 ratingsPLI Basic Training Using VSAM, IMS and DB2 Rating: 1 out of 5 stars1/5Interview Questions for DB2 z/OS Application Developers Rating: 0 out of 5 stars0 ratingsDB2 Exam C2090-616 Practice Questions Rating: 5 out of 5 stars5/5DB2 11 for z/OS: Basic Training for Application Developers Rating: 5 out of 5 stars5/5SQL for eServer i5 and iSeries Rating: 5 out of 5 stars5/5COBOL Language Fundamentals with DB2 Quick Start Rating: 0 out of 5 stars0 ratingsDB2 11 for z/OS: Intermediate Training for Application Developers Rating: 0 out of 5 stars0 ratingsThe iSeries and AS/400 Programmer's Guide to Cool Things Rating: 3 out of 5 stars3/5COBOL Language Fundamentals Quick Start Rating: 0 out of 5 stars0 ratingsSQL Built-In Functions and Stored Procedures: The i5/iSeries Programmer's Guide Rating: 0 out of 5 stars0 ratingsMastering IBM i: The Complete Resource for Today's IBM i System Rating: 3 out of 5 stars3/5IBM Db2 A Complete Guide Rating: 0 out of 5 stars0 ratingsDB2 Interview Questions, Answers, and Explanations: DB2 Database Certification Review Rating: 0 out of 5 stars0 ratingsMvs Jcl in Plain English Rating: 5 out of 5 stars5/5A Guide to Db2 Performance for Application Developers: Code for Performance from the Beginning Rating: 0 out of 5 stars0 ratingsCobol Rating: 0 out of 5 stars0 ratingsCOBOL Programming Interview Questions: COBOL Job Interview Preparation Rating: 5 out of 5 stars5/5zOS JCL (Job Control Language) Rating: 0 out of 5 stars0 ratingsAn Introduction to IBM Rational Application Developer: A Guided Tour Rating: 5 out of 5 stars5/5Understanding AS/400 System Operations Rating: 5 out of 5 stars5/5Mainframe Modernization A Complete Guide - 2019 Edition Rating: 0 out of 5 stars0 ratingsProgramming in RPG IV Rating: 5 out of 5 stars5/5Subfiles in Free-Format RPG: Rules, Examples, Techniques, and Other Cool Stuff Rating: 5 out of 5 stars5/5Mainframe Interview Cases Rating: 0 out of 5 stars0 ratingsCOBOL for the Approved Workman Rating: 0 out of 5 stars0 ratings
Programming For You
Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5HTML & CSS: Learn the Fundaments in 7 Days Rating: 4 out of 5 stars4/5Java for Beginners: A Crash Course to Learn Java Programming in 1 Week Rating: 5 out of 5 stars5/5SQL: For Beginners: Your Guide To Easily Learn SQL Programming in 7 Days Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Machine Learning By Example Rating: 4 out of 5 stars4/5101 Amazing Nintendo NES Facts: Includes facts about the Famicom Rating: 4 out of 5 stars4/5Pokemon Go: Guide + 20 Tips and Tricks You Must Read Hints, Tricks, Tips, Secrets, Android, iOS Rating: 5 out of 5 stars5/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn SQL in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Modern C++ for Absolute Beginners: A Friendly Introduction to C++ Programming Language and C++11 to C++20 Standards Rating: 0 out of 5 stars0 ratingsPython Projects for Beginners: A Ten-Week Bootcamp Approach to Python Programming Rating: 0 out of 5 stars0 ratings
Reviews for DB2 11.1 for LUW
0 ratings0 reviews
Book preview
DB2 11.1 for LUW - Robert Wingate
Introduction
Congratulations on your purchase of DB2 11.1 for LUW: SQL Basic Training for Application Developers! This book will teach you the basic information and skills you need to develop applications with DB2 SQL on IBM distributed computing environments running Linux, UNIX or Windows. The instruction, examples and sample programs in this book are a fast track to becoming productive as quickly as possible using SQL. The content is easy to read and digest, well organized and focused on honing real job skills.
Thanks for your purchase and if you find this SQL basic training guide useful, please leave a positive review at the place you purchased it. I’ll really appreciate that.
Best of luck with your DB2 career!
Robert Wingate
IBM Certified Application Developer – DB2 11 for z/OS
C:\Users\kz4hz\Documents\IBM Books\DB2 LUW 11.1 SQL Quick Reference\Kobo\DB2 LUW 11.1 SQL Basic Training KOBO_files\image001.jpgData Manipulation Language Basics
Overview
Data Manipulation Language (DML) is used to add, change and delete data in a DB2 table. DML is one of the most basic and essential skills you must have as a DB2 professional. In this section we’ll look at the five major DML statements: INSERT, UPDATE, DELETE, MERGE and SELECT.
Database, Tablespace and Schema Conventions
Throughout this book we will be using a database called DBHR which is a database for a fictitious human relations department in a company. We will use storage group SGHR and bufferpool BPHR. The main tablespace we will use is TSHR. Finally, our schema will be HRSCHEMA.
If you are following along and creating examples on your own system, you may of course use whatever database and schema is available to you on your system. At the end of the last chapter we dropped and recreated these objects. If you missed that and want the basic DDL to create the objects named above, here it is:
CREATE DATABASE DBHR
AUTOMATIC STORAGE YES;
CREATE STOGROUP SGHR
ON 'C:' OVERHEAD 6.725
DEVICE READ RATE 100.0
DATA TAG NONE;
CREATE BUFFERPOOL BPHR
IMMEDIATE
ALL DBPARTITIONNUMS SIZE 1000
AUTOMATIC PAGESIZE 4096;
CREATE REGULAR TABLESPACE TSHR
IN DATABASE PARTITION GROUP IBMDEFAULTGROUP
PAGESIZE 4096
MANAGED BY AUTOMATIC STORAGE USING STOGROUP SGHR
AUTORESIZE YES
BUFFERPOOL BPHR
OVERHEAD INHERIT
TRANSFERRATE INHERIT
DROPPED TABLE RECOVERY
ON DATA TAG INHERIT;
CREATE SCHEMA HRSCHEMA
AUTHORIZATION robert; This should be your DB2 id, whatever it is.
DML SQL Statements
Data Manipulation Language (DML) is at the core of working with relational databases. You need to be very comfortable with DML statements: INSERT, UPDATE, DELETE, MERGE and SELECT. We’ll cover the syntax and use of each of these. For purposes of this section, let’s plan and create a very simple table. Here are the columns and data types for our table which we will name EMPLOYEE.
image.jpgThe table can be created with the following DDL:
CREATE TABLE HRSCHEMA.EMPLOYEE(
EMP_ID INT NOT NULL,
EMP_LAST_NAME VARCHAR(30) NOT NULL,
EMP_FIRST_NAME VARCHAR(20) NOT NULL,
EMP_SERVICE_YEARS INT NOT NULL WITH DEFAULT 0,
EMP_PROMOTION_DATE DATE,
PRIMARY KEY(EMP_ID))
IN TSHR;
INSERT Statement
The INSERT statement adds one or more rows to a table. There are two forms of the INSERT statement and you need to know the syntax of each of these.
1. Insert via values
2. Insert via select
Insert Via Values
There are actually two sub-forms of the insert by values. One form explicitly names the target fields and the other does not. Generally when inserting a record you explicitly name the target columns, followed by a VALUES clause that includes the actual values to apply to the columns in the new record. Let’s use our EMPLOYEE table for this example:
INSERT INTO HRSCHEMA.EMPLOYEE
(EMP_ID,
EMP_LAST_NAME,
EMP_FIRST_NAME,
EMP_SERVICE_YEARS,
EMP_PROMOTION_DATE)
VALUES (3217,
'JOHNSON',
'EDWARD',
4,
'01/01/2017');
Updated 1 rows.
A second sub-form of the INSERT statement via values is to omit the target fields and simply provide the VALUES clause. You can do this only if your values clause includes values for ALL the columns in the correct positional order.
Here’s an example of this second sub-form of insert via values for the EMPLOYEE table:
INSERT INTO HRSCHEMA.EMPLOYEE
VALUES (7459,
'STEWART',
'BETTY',
7,
'07/31/2016');
Updated 1 rows.
Note that EMP_ID is defined as a primary key on the table. If you try inserting a row for which the primary key already exists, you will receive a -803 error SQL code (meaning a record already exists with that key).
Here’s an example of specifying the DEFAULT value for the EMP_SERVICE_YEARS column, and the NULL value for the EMP_PROMOTION_DATE.
INSERT INTO HRSCHEMA.EMPLOYEE
(EMP_ID,
EMP_LAST_NAME,
EMP_FIRST_NAME,
EMP_SERVICE_YEARS,
EMP_PROMOTION_DATE)
VALUES (9134,
'FRANKLIN',
'ROSEMARY',
DEFAULT,
NULL);
Updated 1 rows.
When you define a column using WITH DEFAULT, you do not necessarily have to specify an actual default value when you define the table. DB2 provides implicit default values for most data types and if you just specify WITH DEFAULT and no specific value, the implicit default value will be used.
In the EMPLOYEE table we specified WITH DEFAULT 0 for the employee’s service years. However, the implicit default value is also zero because the column is defined as INTEGER. So we could have simply specified WITH DEFAULT and it would have the same result.
We provided this information previously, but it is important enough to repeat it here. The following table provides the default values for the various data types.
Default Values for DB2 Data Types
image.jpgBefore moving on to the Insert via Select option, let’s take a look at the data we have in the table so far.
image.jpgInsert via Select
You can use a SELECT query to extract data from one table and load it to another. You can even include literals or built in functions in the SELECT query in lieu of column names (if you need them). This is often useful for loading tables. Let’s do an example.
Suppose you have an employee recognition request table named EMPRECOG. This table is used to generate/store recognition requests for employees who have been promoted during a certain time frame. HR will print a recognition certificate and deliver it to the employee. Once the request is fulfilled, the date completed will be