iseries SQL Programming: You ve Got the Power!
|
|
|
- Peter Tucker
- 10 years ago
- Views:
Transcription
1 iseries SQL Programming: You ve Got the Power! By Thibault Dambrine On June 6, 1970, Dr. E. F. Codd, an IBM research employee, published "A Relational Model of Data for Large Shared Data Banks," in the Association of Computer Machinery (ACM) journal, Communications of the ACM. This landmark paper still to this day defines the relational database model. The language, Structured English Query Language (known as SEQUEL) was first developed by IBM Corporation, Inc. using Codd's model. SEQUEL later became SQL. Ironically, IBM was not first to bring the first commercial implementation of SQL to market. In 1979, Relational Software, Inc. was, introducing an SQL product named "Oracle". SQL is the ONLY way to access data on Oracle database systems. The ONLY way to access data on Microsoft SQL Server and I could repeat this sentence with a number of other commercial database products. On the iseries however, SQL is NOT the only way to access the data. SQL support has only started with V1R1. At that time, AS/400 SQL performance was a problem a big turnoff for any developer. Because of these facts, many iseries developers still consider SQL as an optional skill. Many still use SQL only as an advanced data viewer utility, in effect, ranking SQL somewhere north of DSPPFM. Today, one can barely get by anymore as a programmer without knowing SQL. The same is true for all commercial database systems. They all support SQL. The iseries is no different. It has evolved to compete. As a programming language, SQL is synonymous with - The ability to do more while coding less than a conventional high-level language like C or RPG - Efficiency while processing large amounts of records in a short period of time - A language offering object-oriented like code recycling opportunities, using SQL Functions and SQL Stored Procedures - Easy to learn and easy to use, SQL is a language that allows one to tell the system what results are required without describing how the data will be extracted This article s first part will describe some common data manipulation methods using SQL. These are from real life applications and they can be applied to a variety of situations. The second part will describe ways to implement SQL code, so that it can be called or evoked by a job scheduler just like any other program on your iseries. SQL on the iseries can be implemented in several methods, some of which include using SQL embedded in C, RPG or other languages. In this article however, I will only concentrate only on "pure" SQL, or SQL that is either interpreted (RUNSQLSTM) or compiled into a function or a stored procedure. IBM has packed a lot of power into iseries SQL. Borrowing Anthony Robbins s words, it is time to "Awaken the Giant Within"! PART 1: CODING IN SQL The Data Unlike most other languages, SQL is not only a language to manipulate data, it is also one that can be used to define the database. In SQL, the category of statements used for this purpose is called Data Definition Language, or DDL. There are many DDL functions, and the point here is not to go through all of them, but I would like to highlight a few that I find most interesting and useful. In DDL: 1) You can define both short (usable in old RPG) and more explicit long fields (usable in SQL). 2) You can define date and time fields with the "DATE" and the "TIMESTAMP" types. This allows date manipulation and date calculations in SQL in a far easier way than in conventional languages. 3) Any table defined in SQL is accessible and mapped by the system like any other file created with DDS. You can do a DSPFD or a DSPFFD with such files just as if they had been created with DDS. Indexes are the same, except they are recognized as Logical Files by the system. Here is an example of this type of definition, with some notes.
2 CREATE TABLE ER100F ( BATCH_ID FOR BTCHID NUMERIC(10), SOURCE_FACILITY FOR SRCFAL CHAR(50), LOAD_TIMESTAMP FOR LDTMSP TIMESTAMP ) ; LABEL ON ER100F (SOURCE_FACILITY TEXT IS 'Source Facility '); LABEL ON ER100F (BATCH_ID TEXT IS 'Batch ID '); LABEL ON ER100F (LOAD_TIMESTAMP TEXT IS 'Load Timestamp '); LABEL ON TABLE ER100F IS 'Test Data Fact Table' ; Note the SOURCE_FACILITY column, defined as CHAR, as opposed to VARCHAR (more common is other SQL implementation). This is because on the iseries, VARCHAR does cause some extra overhead. If you really need to use VARCHAR, you should know that in this type of field, the first two bytes of the field are used to store the length of the field that is occupied with data. For example, if 39 bytes were busy with data out of the 50 bytes available, the number 39 would be in binary in these two bytes. In the past, I also found that using VARCHAR columns for index keys would best be avoided for performance-critical index columns. Note the LOAD_TIMESTAMP column. It is defined as TIMESTAMP. This data type is one of the most valuable in SQL, as one can do data calculations, such as the number of days, hours or minutes between two time stamps. There is also a DATE data type, which is equally useful. Note the "FOR" notation followed by the short field name. This is iseries-specific and it is there so that the programmer can give a long and a short name to a column. Short here, means 10 characters or less. If you decide to use a long name (greater than 10 characters) for your column without specifying a short name with the FOR operand, the system will create a short name for you. For example: If you chose to use "BATCH_NUMBER" (12 characters in all which is allowable in SQL), SQL will assign a 10-character short name for your column which will look like "BATCH00001" and is typically not very meaningful. One more point on creating tables with SQL: To create a table with a source member written like the one above, you have to use the RUNSQLSTM command. The table will be created in your CURRENT LIBRARY. If you wish to create it elsewhere, you have to first change the CURRENT LIBRARY for the job first. Here is an index example: Indexes are visible on the iseries as Logicals in a DSPDBR command: CREATE UNIQUE INDEX ER100FIDX ON ER100F ( BATCH_ID ) On the index, the long or the short names are both valid to specify keys. Note the "UNIQUE" keyword. This is specifying a unique key and is only needed if you do need the key to be unique. With SQL, on the iseries, in addition to creating a UNIQUE INDEX, one has also the option to create a UNIQUE CONSTRAINT. Constraints, however, do not show up on the DSPDBR command. To find constraints, one has to look in the SQL Catalog. Exploring the SQL Catalog The SQL catalog is a repository of all tables, column names, triggers and generally every component relevant to the database. On the iseries, one can locate the SQL Catalog tables in library QSYS2. Note that even tables created originally as files with the CRTPF or CRTLF commands will be recorded in the DB2 SQL Catalog tables. These SQL Catalog tables all start with the letters "SYS". For example, to find the SQL definition of an existing table, you can do a SELECT * FROM QSYS2/SYSCOLUMNS WHERE TABLE_NAME = 'FILE_NAME'. Using SELECT * FROM QSYS2/SYSCHKCST will show all existing constraints in your system. Other SQL catalog files include SYSINDEXES, SYSFUNCS, SYSTRIGGER and SYSVIEWS. Critical Nature of Indexes Often in SQL training sessions, for obvious reasons, the databases used for teaching purposes are small. In these situations, not having an index or not using the best methods produces a result in reasonable time, regardless of the presence or absence of indexes. When processing large amounts of data, absence of an index or using a less than
3 optimal method (which forces SQL to do more disk access than it would otherwise), will magnify inefficiencies and the time it takes to produce results. Another point, which cannot be over-emphasized, when putting together a database for use in SQL, is to ensure that the data within is usable "as is". What I mean here is that if you need a date field, use the DATE data type, not a DEC or CHAR. Ensuring that your data is set in the best data type will mean that you will be able to join tables with indexes that have the same type and do not need to be cast or modified to connect. Altering Tables With Data SQL has the ability to alter a table, even if it already contains data. Effectively, you can add or remove a column on a table without having to temporarily store the data in a work-file and copying it back after re-compiling the table. Note that the ALTER keyword in SQL can also be used for adding or removing constraints and primary keys. Adding a column: ALTER TABLE EQP_TABLE ADD COLUMN EQUIPMENT_CATEGORY FOR EQPCAT CHAR(10) Removing a column: ALTER TABLE EQP_TABLE DROP COLUMN EQUIPMENT_CATEGORY Adding a constraint: ALTER TABLE EQP_TABLE ADD CONSTRAINT NEWID UNIQUE(EQP_ID, PURCH_DATE) Using SQL to create Triggers Another notable SQL feature is its ability to create database triggers. Below, is the syntax for a trigger written with SQL: Trigger syntax CREATE TRIGGER trigger_name Activation _Time Trigger_Event ON table_name REFERENCING OLD AS old_row NEW AS new_row FOR EACH ROW / FOR EACH STATEMENT MODE DB2ROW / DB2SQL WHEN condition BEGIN Trigger body END (DB2ROW triggers are activated on each row operation, DB2SQL triggers are activated after all of the row operations have occurred) Trigger Example (re-printed from IBM Manual) CREATE TRIGGER SAL_ADJ AFTER UPDATE OF SALARY ON EMPLOYEE REFERENCING OLD AS OLD_EMP NEW AS NEW_EMP FOR EACH ROW MODE DB2SQL WHEN (NEW_EMP.SALARY > (OLD_EMP.SALARY *1.20)) BEGIN ATOMIC SIGNAL SQLSTATE '75001'('Invalid Salary Increase - Exceeds 20%'); END BEGIN ATOMIC specifies a list of SQL statements that are to be executed for the triggered-action. The statements are executed in the order in which they are specified. Coding in SQL Join Basics One of the must-have building blocks for coding in SQL is the JOIN statement. This is where all the set logic comes alive. While SQL can handle record-by-record processing using cursors, in most cases, it is most efficient when processing sets of records. Here are the choices we have when joining tables. When two bolded keywords are specified, both syntaxes are correct. One is simply more explicit than the other: A Join or Inner Join returns only the rows from each table that have matching values in the join columns. Any rows that do not have a match between the tables will not appear in the result table. A Left Join or Left Outer Join returns values for all of the rows from the first table (the table on the left) and the values from the second table for the rows that match. Any rows that do not have a match in the second table will return the null value for all columns from the second table. A Right Join or Right Outer Join return values for all of the rows from the second table (the table on the right) and the values from the first table for the rows that match. Any rows that do not have a match in the first table will return the null value for all columns from the first table. A Left Exception Join returns only the rows from the left table that do not have a match in the right table. Columns in the result table that come from the right table have the null value. A Right Exception Join returns only the rows from the right table that do not have a match in the left table. Columns in the result table that come from the left table have the null value. A Cross Join returns a row in the result table for each combination of rows from the tables being joined (also known as a Cartesian Product).
4 The ability to join tables gives the flexibility to assemble data from several sources. It also allows correlations, updates, deletes and verifications. Bringing SQL to life Some common coding examples: Join logic is good to know, but in isolation, it all remains SQL theory. In the following paragraphs, I will describe real life examples and the SQL methods that I have used to resolve these situations. Example 1: Gathering Information from Several Tables Using a Left Outer Join Let us assume that your primary file is the employee master, which is keyed by EMPLOYEE_NBR and your secondary files are the BENEFITS_MASTER and the PAYROLL_MASTER. Both also contain an EMPLOYEE_NBR column. These columns will be the join keys. If a BENEFITS_MASTER or PAYROLL_MASTER record cannot be found for a given key in the primary file, SQL by default will return a NULL value. In this example however, we will intercept NULLs with the IFNULL operand and substitute the NULLs with our own defaults. INSERT INTO EMPLOYEE_DATA ( EMPLOYEE_NBR, EMPLOYEE_NAME, EMPLOYEE_BENEFITS_DESC, EMPLOYEE_SALARY, SALARY_CATEGORY ) SELECT EM.EMPLOYEE_NBR, EM.EMPLOYEE_FIRST_NAME EM.EMPLOYEE_LAST_NAME, IFNULL(BM.EMPLOYEE_BENEFITS_DESC, New Employee Benefits not yet allocated ), IFNULL(PM.YEARLY_SALARY, 0), CASE WHEN PM.YEARLY_SALARY< THEN 'REGULAR EMPLOYEE' WHEN PM.YEARLY_SALARY<= THEN 'EXECUTIVE EMPLOYEE' WHEN PM.YEARLY_SALARY IS NULL THEN 'UNKNOWN - INVESTIGATE' ELSE 'DA BOSS' END FROM EMPLOYEE_MASTER EM LEFT OUTER JOIN BENEFITS_MASTER BM ON EM.EMPLOYEE_NBR = BM.EMPLOYEE_NBR LEFT OUTER JOIN PAYROLL_MASTER PM ON EM.EMPLOYEE_NBR = PM.EMPLOYEE_NBR; A couple of points regarding the example above: - If you have more than one match in the outer join (BENEFITS_MASTER in this case) file, SQL will return as many rows as there are matches. - Left Outer Join is a very efficient model. The example above shows one table (EMPLOYEE_MASTER) joined to a two other tables, the BENEFITS_MASTER and the PAYROLL_MASTER. You can actually add many left outer joins and still get a very efficient retrieval process. In RPG terms, it is similar to putting a read of EMPLOYEE_MASTER in a loop, and for each record, doing a chain to BENEFITS_MASTER and another chain to PAYROLL_MASTER, based upon the returned indicators, putting a default value in the variable and writing the results into EMPLOYEE_DATA. - Of all the SQL techniques, Left Outer Join is one of the most commonly used to extract data. - Note the CASE statement used for filling the SALARY_CATEGORY column. CASE statements give your SQL code the flexibility to transform data, as opposed to only gather data as it is. Think of this in a situation where you are using SQL to do a data conversion project. This is one example where using CASE may be most useful.! " #%$ &&&& Example 2: a) An update in a given table, when based on data stored in another table is described in SQL a "correlated update". In this situation, you have to repeat the same "where" clause 2 times. Note the use of correlation names. The main table, FILEX, is correlated to the name "MAIN". The table on which the decision to update is based, FILEY, is correlated to the name UPDT. Giving the correlation names makes each table s role more obvious in the SQL statement. Note also that once the table is given a correlation name, any column that belongs to it must be qualified with that correlation name, as opposed to the original table name, if you chose to qualify it. UPDATE FILEX MAIN SET (MAIN.FIRST_NAME, MAIN.LAST_NAME) = (SELECT UPDT.FIRST_NAME,UPDT.LAST_NAME FROM FILEY UPDT WHERE MAIN.ID=UPDT.ID) WHERE EXISTS (SELECT DUMMY FROM UPDATE_TABLE UPDT WHERE MAIN.ID=UPDT.ID);
5 ( b) A delete in one table based on data stored in another table is called "correlated delete". Again, here is an example using the WHERE clause two times: DELETE FROM FILEX MAIN WHERE EXISTS (SELECT DUMMY FROM FILEY UPDT WHERE MAIN.ID=UPDT.ID); To formalize the correlation name syntax, one can say it works in the following pattern: SELECT "TABLE_CORRELATION NAME"."COLUMN_NAME1" "COLUMN_CORRELATION NAME" FROM "TABLE_NAME" "TABLE_CORRELATION NAME" Example 3: Finding Duplicate Keys in a Table One of the most common uses for SQL is to identify duplicate values in a raw input table. To find out if there are duplicates, there are several methods, several solutions that you may want to pick from, depending on what you are aiming to do. a) This example will show how to identify duplicates, based on the criteria of three different columns in your table. SELECT ADDRESS_1, ADDRESS_2, ADDRESS_3, COUNT(*) FROM CONTACT_TABLE GROUP BY ADDRESS_1, ADDRESS_2, ADDRESS_3 HAVING COUNT(*) > 1 Note the HAVING clause. It applies only on aggregated values, in this case, the COUNT(*). Note: You cannot do a "WHERE COUNT(*) > 1". The WHERE clause is good only for comparing values in individual rows. b) The example above will show only the key fields of the duplicate rows. If you wish to see the entire row (all the columns), you can use the following method, which joins a table to itself and uses the relative record number, as well as the keys to show the duplicates: SELECT RRN(A1), A1.* FROM CONTACT_TABLE A1 WHERE RRN(A1) < (SELECT MAX(RRN(A2) ) FROM CONTACT_TABLE A2 WHERE ( A1.ADDRESS_1 = A2.ADDRESS_1 AND A1.ADDRESS_2 = A2.ADDRESS_2 AND A1.ADDRESS_3 = A2.ADDRESS_3 ) ) ORDER BY A1.ADDRESS_1, A1.ADDRESS_2, A1.ADDRESS_3 Note on this example the use of correlation names A1 and A2. Here, the use of correlation names allows us to attack the same table as if they were two distinct objects. One thing to remember, if you use a correlation name for a table, it is wise to use that correlation name to qualify any column you retrieve, especially if you join a table to itself. Another point to remember with the code above is that without index, it can be a time-consuming operation if the file is large. c) Of course, once duplicates are identified, you may want to remove them. Assuming the ID_NUMBER in this case is the key we want to keep as unique, the code below will remove all the records lower than the greatest key value. DELETE FROM CONTACT_TABLE A1 WHERE A1.ID_NUMBER < ( SELECT MAX(A2.ID_NUMBER) FROM CONTACT_TABLE A2 WHERE ( A1.ADDRESS_1 = A2.ADDRESS_1 AND A1.ADDRESS_2 = A2.ADDRESS_2 AND A1.ADDRESS_3 = A2.ADDRESS_3 ) ) )* +,$,.- $ 0/21 $ )* %, &% * " * 3 d) ' ( Let s assume for this example that each batch of cash-register data is time-stamped. Imagine for a second that a cash register was polled twice by accident. Or a situation where half the sales came in, the communication was broken by a power failure and a polling re-try retrieved the entire batch again, thus creating duplicates. Using the time-stamp, you would only be interested in the latest data. Here is what you could do in SQL to get this information:
6 SELECT STOREKEY, CLERK, TRANSACTION_NUMBER, ITEM#, SIZE, COLOUR, DOLLAR_AMT, MAX(POLLING_TIME) FROM POLLING_TABLE GROUP BY STOREKEY, CLERK, TRANSACTION_NUMBER, ITEM#, SIZE, COLOUR, DOLLAR_AMT Note that I used the MAX function in the examples above. The MIN function works the same way and returns the smallest value. Example 4: Joining Two Tables with Incompatible Keys The solution to this problem may be casting. Using SQL s casting function, you can transform on the fly the contents of a numeric column into characters and vice-versa. With the transformed key, you can then join to the foreign table with a key that has now compatible data types. The only draw-back to this method is that the indexes will not be used. Because of this, on a large scale, it can become an expensive in terms of time and computing resources. To cast alpha data as numeric, use the following formula: SELECT INT(SUBSTRING(CHARCOLUMNNAME, STARTCHAR, LENGTH)) FROM FILENAME Note that this example also has a substring built-in, meaning we are picking only a portion of column To cast numeric data as alpha, use the following formula: SELECT CAST(INTEGERCOLUMN AS CHAR(5)) FROM FILENAME ("5", in this example, is the length of the character string to convert to) Example 5: Converting JD Edwards dates to readable format using SQL JD Edwards* ERP stores dates in a particular format: - first digit is a 0 for dates prior to Y2K and 1 for dates after Y2K - second and third digits are the last two numbers of a year i.e. for 2005 this value will be "05" - third, fourth and fifth digits are the Julian day (nth day of the year) For example, really translates to November 26, While this works well for a computer, it is not very readable by people. This can be easily changed for reading and reporting with SQL by using the following SQL formula, here is an example: SELECT DATE(CHAR( SDUPMJ)) FROM F4211 Example 6a: Retrieving the N Largest Values of a Column The SLOW Way SQL methods can be mixed and combined to produce different results. This example demonstrates a method to retrieve N of the largest quantities in a data set. In this case, we will use the 5 largest customers, in terms of sales. The example below does have one draw-back it uses a sub-select, which typically is not very efficient, so using this method on a large amount of data may cause a lot of disk access resulting in a hit on performance. SELECT * FROM CUSTOMER A WHERE 5 > (SELECT COUNT(*) FROM CUSTOMER B WHERE B.SALES > A.SALES ) ORDER BY A.SALES DESC Example 6b: Retrieving the N Largest Values of a Column The FAST Way The "FETCH FIRST n ROWS ONLY" clause can help in limiting the ouptut of a query. It is also much more efficient than the query above. In this example, only 5 disk retrieval operations are necessary and if your table is indexed, you will not even need to figure out the order in which to pull the data. SELECT * FROM CUSTOMER A ORDER BY A.SALES DESC FETCH FIRST 5 ROWS ONLY Example 7: Finding distinct values with SQL SQL can conveniently find distinct values in a data set, essentially, giving you only unique values. If for example, you had a mail order business and wanted to know, using the order file, what are the distinct cities from where all the orders came from, you could say: SELECT DISTINCT CITY_NAME, FROM ORDERS ORDER BY CITY_NAME Example 8: Aggregating Data with SQL
7 SQL can aggregate values, such as COUNT(*), SUM(COL_NAME) or AVG(COL_NAME). This method shows how one can display the resulting data by descending order of the aggregated value. The "ORDER BY 2 DESC" notation is not a typo. It means "order by the second argument in descending order". SELECT CITY_NAME, SUM(ORDER_VALUE) FROM ORDERS GROUP BY CITY_NAME ORDER BY 2 DESC A word about NULLs The NULL value is different from a blank value. It is a value equivalent to "unknown". Where a value is not found in a left outer join for example, a NULL is returned by SQL, essentially meaning that this value is unknown. In SQL, one can purposely set a value to NULL by coding: UPDATE TABLE_A SET USER_NAME = NULL However, to use the existence of a NULL for comparison, one has to write UPDATE TABLE_A SET FIRST_NAME =??? WHERE LAST_NAME IS NULL Using the DB2 equivalent of Oracle s DUAL table In Oracle, there is a handy system table named simply "DUAL". It is used when one needs to retrieve system values, such as the system time. The DB2 for iseries equivalent of Oracle s "DUAL" is SYSIBM/SYSDUMMY1. The name is longer than just "DUAL", but it works the same way. Here are two examples with dates. Note the second one, which is used to make date calculations based on today s date. SELECT CHAR( DATE(TIMESTAMP(' '))) FROM SYSIBM/SYSDUMMY1 12/31/05 SELECT CHAR( DATE(TIMESTAMP(' ') +7 DAYS)) FROM SYSIBM/SYSDUMMY1 01/07/06 In part 2 of this article, I will show you how to put it all together and use it in real (production) life. PART 2: Running SQL on iseries In Part 1 of this article, I have covered a number of every-day useful examples of code that can be used for a variety of situations. While impossible to cover all possibilities, it is designed to start the reader into thinking of real-life applications SQL can be used for in a production environment. We are now at the start of Part 2, which will cover the implementation methods in which all these coding examples can be packaged into code that can run or be scheduled like any other object. While running the odd SQL function on an interactive screen can be helpful to debug data problems, there is much more to SQL than being a better version of DSPPFM. The real power of SQL only comes when it is used within an application. There are three ways of running SQL code on the iseries. They are: 1) Interpreted SQL code 2) SQL code embedded in a C, RPG etc high level language program 3) SQL Stored Procedures I will concentrate only on the Interpreted SQL and Stored SQL procedure methods, which use SQL code ONLY. We will not cover SQL embedded in another language. This also means that we will only cover SQL code executable in batch mode. RUNSQLSTM - Running Interpreted SQL Code in Batch Interpreted SQL is a simple method. Write your SQL code into an ordinary source member and use the RUNSQLSTM command to run it. Each SQL statement must end with a semi-colon character if there is more than one statement in an individual source member. No compiling is necessary. The syntax will be checked at run time and logged in a spool file. This type of procedure cannot be debugged using a debugger, but the spooled output is typically explicit and easy to read. There are two base points to remember when using SQL in batch on the iseries. 1) Selects must have an output
8 With few exceptions, the examples shown in Part 1 are of the "SELECT" variety. A "SELECT" SQL statement all by itself works well in interactive mode because the output goes to the screen by default (it can also be configured to output to a file). When using SQL in batch, the output HAS to be directed somewhere. A SELECT in batch all by itself will produce results that will have nowhere to go and this will result in an error. The typical construct is: INSERT INTO EXTRACT SELECT INPUT.FIRST_NAME, INPUT.LAST_NAME, INPUT.SALARY FROM PAYROLL INPUT WHERE (INPUT.SALARY IS > ); In this case, the output of the SELECT statement is directed to the table EXTRACT 2) Set Processing Only When using interpreted SQL on the iseries, one can only process data in sets (as opposed to record-by-record). Recordby-record processing requires the declaration of an SQL CURSOR, and this can only be handled either in a Stored Procedure or in SQL code embedded in an ILE language such as ILE C or ILE RPG, all of which are compiled. Once the source member containing the SQL statement is built, you can execute it in interpreted mode with the following command: RUNSQLSTM SRCFILE(SRCFILLIB/SRCFIL) SRCMBR(SRCMBR). This is a CL command and can be entered into any CL program. SQL Stored Procedures - Running Compiled SQL Code in Batch Creating and running SQL stored procedures is a bit more involved than interpreted SQL, but not by much. The benefit of the extra effort is worthwhile for the following reasons: Stored Procedures 1) Compile into executable objects a. Compiled code runs faster than interpreted code b. With compiled code, one can put the program in debug and retrieve the DB2 SQL Optimizer messages to figure out the best indexes to use 2) Allow the choice of using set processing or record-by-record processing, using SQL cursors 3) Allow programming constructs such as loops and if-then-else conditions 4) Can take advantage of compiled SQL Functions Below, is an example of a short procedure, with a do-loop and a cursor, which enables the SQL code to target data one record (row) at a time. In this case, we are updating the time stamp for each row in a table. The time stamp precision extends to the millionth of a second. Because of this level of precision, each record will be stamped with a unique time stamp value. CREATE PROCEDURE PROC_NAME LANGUAGE SQL -- START PROCEDURE -- This procedure will, for each row of table ER400SX, retrieve the current timestamp -- and update the column PUBLISH_TMS within ER400SX BEGIN -- DECLARE CURSOR VARIABLES DECLARE PUBLISH_TMS TIMESTAMP ; DECLARE WORK_TIMESTAMP TIMESTAMP ; DECLARE SQLSTATE CHAR(5) DEFAULT '00000' ; DECLARE AT_END INT DEFAULT 0 ; DECLARE SQLCODE INT DEFAULT 0 ; DECLARE CURSOR_UPD CURSOR FOR SELECT PUBLISH_TMS FROM ER400SX MAIN; SET AT_END = 0; OPEN CURSOR_UPD ; FETCH_LOOP: LOOP FETCH CURSOR_UPD INTO WORK_TIMESTAMP ; IF SQLCODE = 0 AND SQLSTATE = '00000' THEN UPDATE ER400SX
9 SET PUBLISH_TMS = CURRENT TIMESTAMP, TIME_ELAPSED = DAY(CURRENT_TIME_STAMP WORK_TIMESTAMP) WHERE CURRENT OF CURSOR_UPD ; ELSE SET AT_END = 1 ; LEAVE FETCH_LOOP ; END IF ; END LOOP ; CLOSE CURSOR_UPD ; -- END PROCEDURE END There are several steps to turn this source code into a running, callable program. The first step is to execute the SQL source, as one would with interpreted SQL, using the RUNSQLSTM command we are now familiar with. Because the source code begins with "CREATE PROCEDURE PROC_NAME", running the code with RUNSQLSTM within will effectively trigger the creation of the procedure PROC_NAME. Note that if an object of type *PGM with the same name already exists in your CURRENT LIBRARY, RUNSQLSTM will not replace the object. The compilation will simply crash. If you want to create the procedure elsewhere, change your CURRENT LIBRARY to the desired target library prior to running the RUNSQLSTM command. Assuming there are no syntax errors, an object of type CLE will be created, bearing the name of the procedure that you chose. In effect, the Operating System will wrap your SQL code in ILE C and created an ILE C object. There is one catch with this type of program. Stored Procedures looks like ordinary ILE C programs but cannot be called from the command line. They have to be called from an SQL environment. I say this here because it is not very obvious in the manual. If called from the command line, like any other program, the Stored Procedure object will crash with a "Pointer not set for location referenced" error. The reason for this is that the SQL environment passes hidden parameters when SQL Stored Procedures are called from there. There are four ways to call SQL procedures from an SQL environment: 1) Interactively This is a quick way to test this type of program, provided you are using small data sets. a) Use the STRSQL command to enter an SQL environment. b) From the SQL command line, use the same syntax as you would for any program: CALL LIBNAME/PROC_NAME. This will call the Stored Procedure object and it will end normally. 2) Batch Option 1 This is the simplest way to write code that can be called from a program. It is a bit awkward, but it does work. Remember here that the aim is simply to call the program "from an SQL environment". a) You would first need to create a source member that would have inside "CALL LIBNAME/PROC_NAME" b) A CL program can subsequently run this member with the RUNSQLSTM command. 3) Batch Option 2 This method uses the QMQRY, or Query Manager product. Here again, the aim is to call the program "from an SQL environment". a) In a QMQRY member, type CALL LIBNAME/PROC_NAME. Note that QMQRY offers some flexibility here, you could create a QMQRY designed simply to run procedures and have something like CALL &LIBNAM/&PROC_NAME, where &LIBNAM and &PROC_NAME could be passed as parameters. b) Use the STRQMQRY command to execute the QMQRY member, with or without parameters, depending on how you coded the QM source member. 4) Batch Option 3 This method uses a widely available command called EXCSQL, originally created by Dan Riehl (if IBM could put such a command in the OS, it would be very practical). The EXCSQL command effectively lets you execute individual SQL statements from a CL program. It can be downloaded from the Internet. Once you have built this command on your system, you can do something like EXCSQL REQUEST('CALL LIBNAME/PROC_NAME') There is one more important point on the topic of Stored Procedures. Being procedures, but also being CLE-type programs, they can be debugged. Here is the method to compile a procedure in a way that it can be debugged:
10 Back to the creation of the procedure using RUNSQLSTM, to be able to debug the procedure to be created, use the following option: RUNSQLSTM with DBGVIEW(*LIST) or DBGVIEW(*SOURCE). If you use *LIST, you will have a debug view of the C code generated by the system to wrap around your SQL code. If you use *SOURCE, you will only see your SQL source as you debug it. While the *LIST view is interesting to see, the *SOURCE view is much more convenient for debugging. Once the procedure is compiled, use STRDBG PGM(PROC_NAME) UPDPROD(*YES) from the command line to go into debug mode. The next thing you will see is a screen full of source code. Hit F10 and you will be back to the command line. From there, do a STRSQLSTM and from there, a CALL PROC_NAME. You will be able to step through your program in debug mode. Here are a few of pointers for debugging an SQL procedure: 1) In a Stored procedure, the SQLCODE is a results indicator variable affected by each database operation. A zero value in the SQLCODE indicates success. To see the value of the SQLCODE variable, use EVAL SQLCODE. To see ALL local variables at any point in your C/400 debug session, enter the following command on the debug screen command line: EVAL %LOCALVARS 2) To see the value of a character string in a C/400 debug session, use the following command: EVAL *variablename :s 12 (12 is the length of the string you wish to display) 3). For a more in-depth understanding of what is happening with your latest SQL database operation, if there is a problem, the place to look is a system-maintained data structure named "sqlca". To be able to see the contents of this data structure, in a debug session, use EVAL sqlca (Make sure that "sqlca" is in lower case). This instruction will display the entire SQLCA data structure. Remember, these are C programs and all variables are case-sensitive. For more information, look up IBM Red Book "Stored Procedures, Triggers and User Defined Functions on DB2 Universal Database for iseries". Further definitions of the sqlca data structure are available on IBM s website in the DB2 Application Development Guide. SQL Functions Recycle that Code! One of the features I particularly like about SQL is functions. In the same way that on the iseries, you can create your own commands, you can create your own SQL functions and use them just like any other SQL system-supplied function. While procedures can receive and return many parameters, functions can receive many but will only return a single value. The way functions are implemented on the iseries is as follows. To compile a function, use the RUNSQLSTM command. This will compile the function into an object of type *SRVPGM. This means that the function cannot be called on its own but it can be evoked from within an ILE program or an SQL Stored procedure. Below, is an example using dates to grade an item as fresh, old or very old: CREATE FUNCTION HOW_OLD (INDATE DATE) RETURNS CHAR(8) LANGUAGE SQL BEGIN DECLARE HOW_OLD CHAR(8); DECLARE RETVAL CHAR(8); CASE WHEN INDATE < CURRENT_DATE - 60 DAYS THEN SET RETVAL = 'VERY OLD'; WHEN INDATE < CURRENT_DATE - 30 DAYS THEN SET RETVAL = 'OLD'; ELSE SET RETVAL = 'FRESH'; END CASE; RETURN(RETVAL); END Once built, the HOW_OLD function can be re-used in any number of stored procedures, or even other functions. In a stored procedure, using the HOW_OLD function would be possible with the following syntax: AGE_GRADING = HOW_OLD(DATEVAR) Essentially, the HOW_OLD function has become a black-box, nobody needs to know how it does its work, as long as one knows what it needs and what it will return. Another practical function that can be put to use immediately if your company
11 runs JD Edwards software is a Julian Date conversion function, which would receive the Julian date and return a regular format date (see example 5 in Part 1 of this article). In Real Life Using SQL day-in and day-out, one quickly realizes that SQL is one of these languages where it is deceptively easy to code programs which work well with a small data samples but do not scale well and sit for hours on large data sets. The usual reason for this behavior is either lack of proper indexes or a choice of SQL method that is not optimum. There are some basic rules to avoid this type of situation: 1) Indexes, Indexes, Indexes. For best performance, it is well worth to ensure indexes are present with the keys you will use in your joins. If possible, create your indexes with the keys of lowest cardinality first and highest cardinality last. This will also speed up the processing. Code your SQL join statements with keys that match the order of the indexes you created. Consider building new indexes if none of the existing ones fit your current requirement. The SQL Optimizer, part of the operating system, will look for the best combination of indexes for you. 2) Use proper data types: If at all possible, store data in such a way that you will not need to manipulate it for example, use numeric types for numbers, date or timestamps types for dates. SQL has powerful casting functions but as mentioned previously, when you start using function results as part of a join, existing indexes cannot be used. 3) Don t be afraid to use work files. There are times when you can achieve better performance by using several simple SQL instructions with intermediate work tables than by trying to cram everything into one long and overly sophisticated command. 4) Maintainability and performance: These are goals to shoot for. Example 6, in Part 1 of this article demonstrated a method to retrieve N of the largest quantities in a data set with a single SQL statement. This SQL statement, while elegant, accomplished its goal with a high IO cost. No problem on a small table, but on a large set, it is an expensive statement. This is an example where a cursor could be more efficient, having the ability to retrieve the N biggest amounts from a table with exactly N accesses to the database using a descending order index to read the table no matter how big the table is. With experience, you will become better at figuring the most efficient SQL method for a given situation. This is one where you learn every day. The more you use it, the more you learn. 5) Interpreted vs. Compiled: The RUNSQLSTM interprets the SQL commands written in a source member. This is the fastest way to implement data set processing SQL code. Stored procedures are compiled, which means a few extra steps to implement and the necessity to manage objects as well as source. Stored procedures allow both data set processing and row-by-row processing using cursors. They typically run faster than interpreted code, and also allow one to figure out what the SQL Optimizer needs to do its job most efficiently. For large volume applications, where processing speed is critical, you may want to consider stored procedures. Method to find the SQL Optimizer suggestions to improve program or stored procedure SQL performance The DB2 Optimizer is part of the iseries OS. The purpose of this operating system component is to ensure any SQL statement submitted on the system will use the most efficient access path available to retrieve the data. If you find your SQL stored procedure does not run as fast as you expected it to, with the method explained below, you can find out what indexes the DB2 optimizer is looking for in terms of indexes. This method is also valid for SQL embedded in C or RPG. 1) Go in debug and change the job to record all activities and second level text STRDBG UPDPROD(*YES) CHGJOB LOG(4 4 *SECLVL) Note: with *SECLVL, both the message text and the message help (cause and recovery) of the error message are written to the job log. 2) Call the Stored Procedure from within an SQL environment (STRSQL and do "CALL LIBNAM/PROC_NAME" from the SQL command line or RUNSQLSTM of a member containing "CALL LIBNAM/PROC_NAME") 3) SIGNOFF LOG(*LIST) (I use this method, as opposed to looking at the joblog because it is easier to scan a spool file) 4) Signon again and look for your last job log with WRKSPLF (the name of the file will be QPJOBLOG) In that spool file, find the following character strings: **** Starting optimizer debug message for query and Access path suggestion for file (Note: DB2 Optimizer suggestions may or may not appear) They will show you what the SQL optimizer is looking for and the suggestions it may have made for you to improve the
12 performance of your SQL code. Typically the Optimizer will suggest indexes, with precise key orders. Once you know what the Optimizer wants, you build the suggested indexes and re-run your job. Nine times out of ten, you should see a significant performance improvement in your SQL job. Note that this method is also valid for SQL embedded in C or other languages. Another tool that can yield useful information is the PRTSQLINF command. It prints the query implementation plan contents for any high level language program, stored procedure or service program with embedded static SQL. PRTSQLINF produces a spooled file containing the query optimizer index choices for the SQL statements contained in the program or procedure. Knowing what indexes the optimizer is planning to use may save you some debugging time. Keep in mind that PRTSQLINF does not make index suggestions. Implementation Considerations One of the critical considerations if you are going to start using SQL for production programs is your promotion control software. Basically, if you cannot promote it, you cannot use it very conveniently or on a larger scale. Promoting SQL procedures to a production environment means different steps from a traditional compilation have to be executed. They are not very complicated but they are different. If you are aiming to use SQL in production jobs, do look at this particular aspect ahead of time. Make sure your implementation software can handle SQL code. In Conclusion: What s Next? SQL is a vast topic. In this article, we only scratched the surface. The diagram below is copied from an IBM presentation titled "Tuning Web-based Data Access for DB2 UDB for iseries". ODBC / JDBC / ADO / DRDA / XDA Clients Network Host Server CLI / JDBC Native (Record I/O) Dynamic Prepare Every Time Static Compiled embedded Statements Extended Dynamic Prepare once and then Reference SQL SQL Optimizer DB2 UDB for iseries Take note of the contrast between the left side (the Native Record I/O) vs. the right side (the SQL-based access) of the diagram. Clearly, IBM is investing in SQL-based connectivity, making the iseries database compatible with - and accessible via all the leading data exchange protocols. To remain competitive in the now highly commoditized server market, the iseries, long considered a niche machine, now supports the following client protocols: - ODBC - Open Data Base Connectivity, a standard database access method developed by the SQL Access Group to make it possible to access any data from any application, regardless of which database management system (DBMS) is handling the data. - CLI - Call Level Interface (DB2 CLI) is IBM's callable SQL interface to the DB2 family of database servers. It is a 'C' and 'C++' application programming interface for relational database access that uses function calls to pass dynamic SQL statements as function arguments. - JDBC, Java Database Connectivity, a Java API that enables Java programs to execute SQL statements. This allows Java programs to interact with any SQL-compliant database. - ADO, ActiveX Data Objects, Microsoft's high-level interface for data objects.
13 - DRDA, Distributed Relational Database Architecture, an IBM standard for accessing database information across IBM platforms that follows SQL standards. - XDA, Extensible Distributed Architecture, an enterprise architecture for distributed, high-performance, object-oriented, applications. All arrows point to SQL as a base layer for modern iseries database development and connectivity. This is now a base necessity to be competitive as a programmer. Are you fluent with SQL yet? Right now, you can be. On your iseries, you ve got the power. The author acknowledges the proof-readers who contributed generously to this article.
Physical File. Collection or Schema
! "#$ %! iseries Library Physical File Record Field Logical File SQL Collection or Schema Table Row Column View or Index ! &! '!$ $ ()*++,, $,-.".".),-/ 0$1 234 5$ $,6 % '7 - -!# 8-9-,7-8 - %%.).-'-9 '!-
SQL Basics for RPG Developers
SQL Basics for RPG Developers Chris Adair Manager of Application Development National Envelope Vice President/Treasurer Metro Midrange Systems Assoc. SQL HISTORY Structured English Query Language (SEQUEL)
Intro to Embedded SQL Programming for ILE RPG Developers
Intro to Embedded SQL Programming for ILE RPG Developers Dan Cruikshank DB2 for i Center of Excellence 1 Agenda Reasons for using Embedded SQL Getting started with Embedded SQL Using Host Variables Using
Using AS/400 Database Monitor To Identify and Tune SQL Queries
by Rick Peterson Dale Weber Richard Odell Greg Leibfried AS/400 System Performance IBM Rochester Lab May 2000 Page 1 Table of Contents Introduction... Page 4 What is the Database Monitor for AS/400 tool?...
4 Simple Database Features
4 Simple Database Features Now we come to the largest use of iseries Navigator for programmers the Databases function. IBM is no longer developing DDS (Data Description Specifications) for database definition,
2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA www.sybex.com
Essential SQL 2 Essential SQL This bonus chapter is provided with Mastering Delphi 6. It is a basic introduction to SQL to accompany Chapter 14, Client/Server Programming. RDBMS packages are generally
Using SQL in RPG Programs: An Introduction
Using SQL in RPG Programs: An Introduction OCEAN Technical Conference Catch the Wave Susan M. Gantner susan.gantner @ partner400.com www.partner400.com Your partner in AS/400 and iseries Education Copyright
2 SQL in iseries Navigator
2 SQL in iseries Navigator In V4R4, IBM added an SQL scripting tool to the standard features included within iseries Navigator and has continued enhancing it in subsequent releases. Because standard features
A Brief Introduction to MySQL
A Brief Introduction to MySQL by Derek Schuurman Introduction to Databases A database is a structured collection of logically related data. One common type of database is the relational database, a term
Advanced SQL. Jim Mason. www.ebt-now.com Web solutions for iseries engineer, build, deploy, support, train 508-728-4353. jemason@ebt-now.
Advanced SQL Jim Mason [email protected] www.ebt-now.com Web solutions for iseries engineer, build, deploy, support, train 508-728-4353 What We ll Cover SQL and Database environments Managing Database
How To Create A Table In Sql 2.5.2.2 (Ahem)
Database Systems Unit 5 Database Implementation: SQL Data Definition Language Learning Goals In this unit you will learn how to transfer a logical data model into a physical database, how to extend or
Embedded SQL programming
Embedded SQL programming http://www-136.ibm.com/developerworks/db2 Table of contents If you're viewing this document online, you can click any of the topics below to link directly to that section. 1. Before
Retrieving Data Using the SQL SELECT Statement. Copyright 2006, Oracle. All rights reserved.
Retrieving Data Using the SQL SELECT Statement Objectives After completing this lesson, you should be able to do the following: List the capabilities of SQL SELECT statements Execute a basic SELECT statement
ERserver. DB2 Universal Database for iseries SQL Programming with Host Languages. iseries. Version 5
ERserver iseries DB2 Universal Database for iseries SQL Programming with Host Languages Version 5 ERserver iseries DB2 Universal Database for iseries SQL Programming with Host Languages Version 5 Copyright
SQL Server Database Coding Standards and Guidelines
SQL Server Database Coding Standards and Guidelines http://www.sqlauthority.com Naming Tables: Stored Procs: Triggers: Indexes: Primary Keys: Foreign Keys: Defaults: Columns: General Rules: Rules: Pascal
www.gr8ambitionz.com
Data Base Management Systems (DBMS) Study Material (Objective Type questions with Answers) Shared by Akhil Arora Powered by www. your A to Z competitive exam guide Database Objective type questions Q.1
Information Systems SQL. Nikolaj Popov
Information Systems SQL Nikolaj Popov Research Institute for Symbolic Computation Johannes Kepler University of Linz, Austria [email protected] Outline SQL Table Creation Populating and Modifying
MAS 500 Intelligence Tips and Tricks Booklet Vol. 1
MAS 500 Intelligence Tips and Tricks Booklet Vol. 1 1 Contents Accessing the Sage MAS Intelligence Reports... 3 Copying, Pasting and Renaming Reports... 4 To create a new report from an existing report...
SQL Server An Overview
SQL Server An Overview SQL Server Microsoft SQL Server is designed to work effectively in a number of environments: As a two-tier or multi-tier client/server database system As a desktop database system
Maintaining Stored Procedures in Database Application
Maintaining Stored Procedures in Database Application Santosh Kakade 1, Rohan Thakare 2, Bhushan Sapare 3, Dr. B.B. Meshram 4 Computer Department VJTI, Mumbai 1,2,3. Head of Computer Department VJTI, Mumbai
Oracle 10g PL/SQL Training
Oracle 10g PL/SQL Training Course Number: ORCL PS01 Length: 3 Day(s) Certification Exam This course will help you prepare for the following exams: 1Z0 042 1Z0 043 Course Overview PL/SQL is Oracle's Procedural
SQL - QUICK GUIDE. Allows users to access data in relational database management systems.
http://www.tutorialspoint.com/sql/sql-quick-guide.htm SQL - QUICK GUIDE Copyright tutorialspoint.com What is SQL? SQL is Structured Query Language, which is a computer language for storing, manipulating
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
Test: Final Exam Semester 1 Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 6 1. The following code does not violate any constraints and will
Performance Tuning for the Teradata Database
Performance Tuning for the Teradata Database Matthew W Froemsdorf Teradata Partner Engineering and Technical Consulting - i - Document Changes Rev. Date Section Comment 1.0 2010-10-26 All Initial document
Oracle Database: SQL and PL/SQL Fundamentals
Oracle University Contact Us: 1.800.529.0165 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This course is designed to deliver the fundamentals of SQL and PL/SQL along
Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff
D80198GC10 Oracle Database 12c SQL and Fundamentals Summary Duration Vendor Audience 5 Days Oracle End Users, Developers, Technical Consultants and Support Staff Level Professional Delivery Method Instructor-led
Instant SQL Programming
Instant SQL Programming Joe Celko Wrox Press Ltd. INSTANT Table of Contents Introduction 1 What Can SQL Do for Me? 2 Who Should Use This Book? 2 How To Use This Book 3 What You Should Know 3 Conventions
Commercial Database Software Development- A review.
Commercial Database Software Development- A review. A database software has wide applications. A database software is used in almost all the organizations. Over 15 years many tools have been developed
Oracle Database: SQL and PL/SQL Fundamentals NEW
Oracle University Contact Us: + 38516306373 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training delivers the
DBMS / Business Intelligence, SQL Server
DBMS / Business Intelligence, SQL Server Orsys, with 30 years of experience, is providing high quality, independant State of the Art seminars and hands-on courses corresponding to the needs of IT professionals.
How To Use The Correlog With The Cpl Powerpoint Powerpoint Cpl.Org Powerpoint.Org (Powerpoint) Powerpoint (Powerplst) And Powerpoint 2 (Powerstation) (Powerpoints) (Operations
orrelog SQL Table Monitor Adapter Users Manual http://www.correlog.com mailto:[email protected] CorreLog, SQL Table Monitor Users Manual Copyright 2008-2015, CorreLog, Inc. All rights reserved. No part
Database Administration with MySQL
Database Administration with MySQL Suitable For: Database administrators and system administrators who need to manage MySQL based services. Prerequisites: Practical knowledge of SQL Some knowledge of relational
1 Structured Query Language: Again. 2 Joining Tables
1 Structured Query Language: Again So far we ve only seen the basic features of SQL. More often than not, you can get away with just using the basic SELECT, INSERT, UPDATE, or DELETE statements. Sometimes
A basic create statement for a simple student table would look like the following.
Creating Tables A basic create statement for a simple student table would look like the following. create table Student (SID varchar(10), FirstName varchar(30), LastName varchar(30), EmailAddress varchar(30));
COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries
COMP 5138 Relational Database Management Systems Week 5 : Basic COMP5138 "Relational Database Managment Systems" J. Davis 2006 5-1 Today s Agenda Overview Basic Queries Joins Queries Aggregate Functions
14 Triggers / Embedded SQL
14 Triggers / Embedded SQL COMS20700 Databases Dr. Essam Ghadafi TRIGGERS A trigger is a procedure that is executed automatically whenever a specific event occurs. You can use triggers to enforce constraints
Guide to the Superbase. ODBC Driver. By Superbase Developers plc
Guide to the Superbase ODBC Driver By Superbase Developers plc This manual was produced using Doc-To-Help, by WexTech Systems, Inc. WexTech Systems, Inc. 310 Madison Avenue, Suite 905 New York, NY 10017
Database Programming with PL/SQL: Learning Objectives
Database Programming with PL/SQL: Learning Objectives This course covers PL/SQL, a procedural language extension to SQL. Through an innovative project-based approach, students learn procedural logic constructs
SQL Server. 2012 for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach
TRAINING & REFERENCE murach's SQL Server 2012 for developers Bryan Syverson Joel Murach Mike Murach & Associates, Inc. 4340 N. Knoll Ave. Fresno, CA 93722 www.murach.com [email protected] Expanded
Chapter 1: Introduction. Database Management System (DBMS) University Database Example
This image cannot currently be displayed. Chapter 1: Introduction Database System Concepts, 6 th Ed. See www.db-book.com for conditions on re-use Database Management System (DBMS) DBMS contains information
MOC 20461C: Querying Microsoft SQL Server. Course Overview
MOC 20461C: Querying Microsoft SQL Server Course Overview This course provides students with the knowledge and skills to query Microsoft SQL Server. Students will learn about T-SQL querying, SQL Server
Oracle SQL. Course Summary. Duration. Objectives
Oracle SQL Course Summary Identify the major structural components of the Oracle Database 11g Create reports of aggregated data Write SELECT statements that include queries Retrieve row and column data
SQL. Short introduction
SQL Short introduction 1 Overview SQL, which stands for Structured Query Language, is used to communicate with a database. Through SQL one can create, manipulate, query and delete tables and contents.
SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package 7 2015-11-24. Data Federation Administration Tool Guide
SAP Business Objects Business Intelligence platform Document Version: 4.1 Support Package 7 2015-11-24 Data Federation Administration Tool Guide Content 1 What's new in the.... 5 2 Introduction to administration
MyOra 3.0. User Guide. SQL Tool for Oracle. Jayam Systems, LLC
MyOra 3.0 SQL Tool for Oracle User Guide Jayam Systems, LLC Contents Features... 4 Connecting to the Database... 5 Login... 5 Login History... 6 Connection Indicator... 6 Closing the Connection... 7 SQL
FileMaker 11. ODBC and JDBC Guide
FileMaker 11 ODBC and JDBC Guide 2004 2010 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker is a trademark of FileMaker, Inc. registered
Darshan Institute of Engineering & Technology PL_SQL
Explain the advantages of PL/SQL. Advantages of PL/SQL Block structure: PL/SQL consist of block of code, which can be nested within each other. Each block forms a unit of a task or a logical module. PL/SQL
Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia
Topics Advanced PL/SQL, Integration with PROIV SuperLayer and use within Glovia 1. SQL Review Single Row Functions Character Functions Date Functions Numeric Function Conversion Functions General Functions
BCA. Database Management System
BCA IV Sem Database Management System Multiple choice questions 1. A Database Management System (DBMS) is A. Collection of interrelated data B. Collection of programs to access data C. Collection of data
1 File Processing Systems
COMP 378 Database Systems Notes for Chapter 1 of Database System Concepts Introduction A database management system (DBMS) is a collection of data and an integrated set of programs that access that data.
Chapter 9, More SQL: Assertions, Views, and Programming Techniques
Chapter 9, More SQL: Assertions, Views, and Programming Techniques 9.2 Embedded SQL SQL statements can be embedded in a general purpose programming language, such as C, C++, COBOL,... 9.2.1 Retrieving
Oracle Database: SQL and PL/SQL Fundamentals
Oracle University Contact Us: +966 12 739 894 Oracle Database: SQL and PL/SQL Fundamentals Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals training is designed to
Tips and Tricks SAGE ACCPAC INTELLIGENCE
Tips and Tricks SAGE ACCPAC INTELLIGENCE 1 Table of Contents Auto e-mailing reports... 4 Automatically Running Macros... 7 Creating new Macros from Excel... 8 Compact Metadata Functionality... 9 Copying,
Oracle Database 10g: Introduction to SQL
Oracle University Contact Us: 1.800.529.0165 Oracle Database 10g: Introduction to SQL Duration: 5 Days What you will learn This course offers students an introduction to Oracle Database 10g database technology.
Guide to Performance and Tuning: Query Performance and Sampled Selectivity
Guide to Performance and Tuning: Query Performance and Sampled Selectivity A feature of Oracle Rdb By Claude Proteau Oracle Rdb Relational Technology Group Oracle Corporation 1 Oracle Rdb Journal Sampled
Introduction to SQL for Data Scientists
Introduction to SQL for Data Scientists Ben O. Smith College of Business Administration University of Nebraska at Omaha Learning Objectives By the end of this document you will learn: 1. How to perform
Using SQL Server Management Studio
Using SQL Server Management Studio Microsoft SQL Server Management Studio 2005 is a graphical tool for database designer or programmer. With SQL Server Management Studio 2005 you can: Create databases
MySQL for Beginners Ed 3
Oracle University Contact Us: 1.800.529.0165 MySQL for Beginners Ed 3 Duration: 4 Days What you will learn The MySQL for Beginners course helps you learn about the world's most popular open source database.
Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.
est: Final Exam Semester 1 Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer. Section 6 1. How can you retrieve the error code and error message of any
LOBs were introduced back with DB2 V6, some 13 years ago. (V6 GA 25 June 1999) Prior to the introduction of LOBs, the max row size was 32K and the
First of all thanks to Frank Rhodes and Sandi Smith for providing the material, research and test case results. You have been working with LOBS for a while now, but V10 has added some new functionality.
SQL Server Query Tuning
SQL Server Query Tuning A 12-Step Program By Thomas LaRock, Technical Evangelist and Head Geek Confio Software 4772 Walnut Street, Suite 100 Boulder, CO 80301 www.confio.com Introduction Query tuning is
D61830GC30. MySQL for Developers. Summary. Introduction. Prerequisites. At Course completion After completing this course, students will be able to:
D61830GC30 for Developers Summary Duration Vendor Audience 5 Days Oracle Database Administrators, Developers, Web Administrators Level Technology Professional Oracle 5.6 Delivery Method Instructor-led
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification
Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 Outline More Complex SQL Retrieval Queries
Database Query 1: SQL Basics
Database Query 1: SQL Basics CIS 3730 Designing and Managing Data J.G. Zheng Fall 2010 1 Overview Using Structured Query Language (SQL) to get the data you want from relational databases Learning basic
Migrate AS 400 Applications to Linux
Migrate AS 400 Applications to Linux Infinite Corporation White Paper date March 2011 Abstract: This paper is a discussion of how to create platform independence by executing i OS (AS/400) applications
A Comparison of Database Query Languages: SQL, SPARQL, CQL, DMX
ISSN: 2393-8528 Contents lists available at www.ijicse.in International Journal of Innovative Computer Science & Engineering Volume 3 Issue 2; March-April-2016; Page No. 09-13 A Comparison of Database
References & SQL Tips
References & SQL Tips Speaker: David Larsen ([email protected]), Software Engineer at Lagoon Corporation Topic: SQL Tips and Techniques on the IBM i Date: Wednesday, January 14th, 2015 Time: 11:00
SPSS: Getting Started. For Windows
For Windows Updated: August 2012 Table of Contents Section 1: Overview... 3 1.1 Introduction to SPSS Tutorials... 3 1.2 Introduction to SPSS... 3 1.3 Overview of SPSS for Windows... 3 Section 2: Entering
Choosing a Data Model for Your Database
In This Chapter This chapter describes several issues that a database administrator (DBA) must understand to effectively plan for a database. It discusses the following topics: Choosing a data model for
Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??
Week 1 Part 1: An Introduction to Database Systems Databases and DBMSs Data Models and Data Independence Concurrency Control and Database Transactions Structure of a DBMS DBMS Languages Databases and DBMSs
3.GETTING STARTED WITH ORACLE8i
Oracle For Beginners Page : 1 3.GETTING STARTED WITH ORACLE8i Creating a table Datatypes Displaying table definition using DESCRIBE Inserting rows into a table Selecting rows from a table Editing SQL buffer
ICOM 6005 Database Management Systems Design. Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001
ICOM 6005 Database Management Systems Design Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department Lecture 2 August 23, 2001 Readings Read Chapter 1 of text book ICOM 6005 Dr. Manuel
Database SQL messages and codes
System i Database SQL messages and codes Version 5 Release 4 System i Database SQL messages and codes Version 5 Release 4 Note Before using this information and the product it supports, read the information
INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3
INTEGRATING MICROSOFT DYNAMICS CRM WITH SIMEGO DS3 Often the most compelling way to introduce yourself to a software product is to try deliver value as soon as possible. Simego DS3 is designed to get you
Embedding SQL in High Level Language Programs
Embedding SQL in High Level Language Programs Alison Butterill IBM i Product Manager Power Systems Agenda Introduction Basic SQL within a HLL program Processing multiple records Error detection Dynamic
Specifications of Paradox for Windows
Specifications of Paradox for Windows Appendix A 1 Specifications of Paradox for Windows A IN THIS CHAPTER Borland Database Engine (BDE) 000 Paradox Standard Table Specifications 000 Paradox 5 Table Specifications
Intro to Databases. ACM Webmonkeys 2011
Intro to Databases ACM Webmonkeys 2011 Motivation Computer programs that deal with the real world often need to store a large amount of data. E.g.: Weather in US cities by month for the past 10 years List
IBM Power Systems Software. The ABCs of Coding High Performance SQL Apps DB2 for IBM i. Presented by Jarek Miszczyk IBM Rochester, ISV Enablement
The ABCs of Coding High Performance SQL Apps DB2 for IBM i Presented by Jarek Miszczyk IBM Rochester, ISV Enablement 2008 IBM Corporation SQL Interfaces ODBC / JDBC / ADO / DRDA / XDA Network Host Server
SQL and Programming Languages. SQL in Programming Languages. Applications. Approaches
SQL and Programming Languages SQL in Programming Languages Read chapter 5 of Atzeni et al. BD: Modelli e Linguaggi di Interrogazione and section 8.4 of Garcia-Molina The user does not want to execute SQL
FileMaker 12. ODBC and JDBC Guide
FileMaker 12 ODBC and JDBC Guide 2004 2012 FileMaker, Inc. All Rights Reserved. FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, California 95054 FileMaker and Bento are trademarks of FileMaker, Inc.
SQL Pass-Through and the ODBC Interface
SQL Pass-Through and the ODBC Interface Jessica Hampton, CIGNA Corporation, Bloomfield, CT ABSTRACT Does SAS implicit SQL pass-through sometimes fail to meet your needs? Do you sometimes need to communicate
Developing SQL and PL/SQL with JDeveloper
Seite 1 von 23 Developing SQL and PL/SQL with JDeveloper Oracle JDeveloper 10g Preview Technologies used: SQL, PL/SQL An Oracle JDeveloper Tutorial September 2003 Content This tutorial walks through the
Oracle Database 10g Express
Oracle Database 10g Express This tutorial prepares the Oracle Database 10g Express Edition Developer to perform common development and administrative tasks of Oracle Database 10g Express Edition. Objectives
History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)
Relational Database Languages Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG) Domain relational calculus QBE (used in Access) History of SQL Standards:
Title. Syntax. stata.com. odbc Load, write, or view data from ODBC sources. List ODBC sources to which Stata can connect odbc list
Title stata.com odbc Load, write, or view data from ODBC sources Syntax Menu Description Options Remarks and examples Also see Syntax List ODBC sources to which Stata can connect odbc list Retrieve available
SQL Server 2008 Core Skills. Gary Young 2011
SQL Server 2008 Core Skills Gary Young 2011 Confucius I hear and I forget I see and I remember I do and I understand Core Skills Syllabus Theory of relational databases SQL Server tools Getting help Data
Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics
Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics Structured Query Language HANS- PETTER HALVORSEN, 2014.03.03 Faculty of Technology, Postboks 203,
CHAPTER 1: CLIENT/SERVER INTEGRATED DEVELOPMENT ENVIRONMENT (C/SIDE)
Chapter 1: Client/Server Integrated Development Environment (C/SIDE) CHAPTER 1: CLIENT/SERVER INTEGRATED DEVELOPMENT ENVIRONMENT (C/SIDE) Objectives Introduction The objectives are: Discuss Basic Objects
What is a database? COSC 304 Introduction to Database Systems. Database Introduction. Example Problem. Databases in the Real-World
COSC 304 Introduction to Systems Introduction Dr. Ramon Lawrence University of British Columbia Okanagan [email protected] What is a database? A database is a collection of logically related data for
Once the schema has been designed, it can be implemented in the RDBMS.
2. Creating a database Designing the database schema... 1 Representing Classes, Attributes and Objects... 2 Data types... 5 Additional constraints... 6 Choosing the right fields... 7 Implementing a table
Basic Unix/Linux 1. Software Testing Interview Prep
Basic Unix/Linux 1 Programming Fundamentals and Concepts 2 1. What is the difference between web application and client server application? Client server application is designed typically to work in a
Oracle Database: SQL and PL/SQL Fundamentals NEW
Oracle University Contact Us: 001-855-844-3881 & 001-800-514-06-97 Oracle Database: SQL and PL/SQL Fundamentals NEW Duration: 5 Days What you will learn This Oracle Database: SQL and PL/SQL Fundamentals
C H A P T E R Condition Handling
ch05.fm Page 75 Wednesday, November 13, 2002 7:16 AM 5 C H A P T E R Condition Handling In this chapter, you will learn: what SQLCODE and SQLSTATE are, and the difference between them. what a condition
IT2305 Database Systems I (Compulsory)
Database Systems I (Compulsory) INTRODUCTION This is one of the 4 modules designed for Semester 2 of Bachelor of Information Technology Degree program. CREDITS: 04 LEARNING OUTCOMES On completion of this
Querying Microsoft SQL Server
Course 20461C: Querying Microsoft SQL Server Module 1: Introduction to Microsoft SQL Server 2014 This module introduces the SQL Server platform and major tools. It discusses editions, versions, tools used
Testing Web Applications for SQL Injection Sam Shober [email protected]
Testing Web Applications for SQL Injection Sam Shober [email protected] Abstract: This paper discusses the SQL injection vulnerability, its impact on web applications, methods for pre-deployment and
In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina
This Lecture Database Systems Lecture 5 Natasha Alechina The language, the relational model, and E/R diagrams CREATE TABLE Columns Primary Keys Foreign Keys For more information Connolly and Begg chapter
ODBC Client Driver Help. 2015 Kepware, Inc.
2015 Kepware, Inc. 2 Table of Contents Table of Contents 2 4 Overview 4 External Dependencies 4 Driver Setup 5 Data Source Settings 5 Data Source Setup 6 Data Source Access Methods 13 Fixed Table 14 Table
JD Edwards World. Database Audit Manager Release A9.3 E21957-02
JD Edwards World Database Audit Manager Release A9.3 E21957-02 April 2013 JD Edwards World Database Audit Manager, Release A9.3 E21957-02 Copyright 2013, Oracle and/or its affiliates. All rights reserved.
