Presentation is loading. Please wait.

Presentation is loading. Please wait.

Appendix B© copyright Janson Industries 20111 SQL ▮ Explain basic SQL concepts ▮ Demonstrate SQL commands ▮ Results Sets.

Similar presentations


Presentation on theme: "Appendix B© copyright Janson Industries 20111 SQL ▮ Explain basic SQL concepts ▮ Demonstrate SQL commands ▮ Results Sets."— Presentation transcript:

1 Appendix B© copyright Janson Industries 20111 SQL ▮ Explain basic SQL concepts ▮ Demonstrate SQL commands ▮ Results Sets

2 Appendix B© copyright Janson Industries 20112 What is SQL? ▮ Standard relational data base data definition and manipulation language ▮ Supported by most relational database management systems (RDBMS) ▮ Has its own terminology but provides standard relational functions

3 Appendix B© copyright Janson Industries 20113 SQL objects Tables - hold all stored data Views - provide an alternative look at data stored in tables (I.e. project and select functions) Index - provides an alternative access to table data (I.e. keys) Schema - directory of all SQL objects. Also contains SQL required information (e.g. field/table/view/index cross reference, data definition, data dictionary, table update journal, etc.)

4 Appendix B© copyright Janson Industries 20114 SQL commands ▮ Create XXXX allows you to create SQL objects: ▮ CREATE SCHEMA ▮ CREATE TABLE ▮ CREATE VIEW ▮ CREATE INDEX

5 Appendix B© copyright Janson Industries 20115 Collections/Schemas ▮ Creating a schema may take some time ▮ A series of objects (indices, journals, journal receivers) are created within the schema ▮ Also, you usually need a high level of authority to create a schema ▮ The schema name is one half of a fully qualified SQL table name ▮ YOURSCH01/INV or YOURSCH01.INV

6 Appendix B© copyright Janson Industries 20116 Tables ▮ When creating a table you must define fields ▮ CREATE TABLE MYSCH01/INV (ITEMNAM CHAR(10), ITEMNUM CHAR(6), PRICE DEC(8,2), DESCR CHAR(25)) ▮ At least a single space between commands, keywords, and field names

7 Appendix B© copyright Janson Industries 20117 Loading data ▮ Insert Into table name Values (‘char data’, numeric data, ‘char data’,...) ▮ INSERT INTO MYSCH01/INV VALUES (‘Hammer’, ‘111111 ’, 14.95, ‘ 12 inch claw’)

8 Appendix B© copyright Janson Industries 20118 Viewing data ▮ Select field names From table name Where select condition ▮ SELECT ITEMNAM, PRICE FROM MYSCH01/INV WHERE PRICE >.99 ▮ Returns those rows that satisfy the WHERE condition ▮ Select very powerful and can be used to enhance other commands

9 Appendix B© copyright Janson Industries 20119 Subselects ▮ INSERT INTO MYSCH01/INV SELECT * FROM MYLIB01/INV ▮ Asterisk means all (in this case all fields) ▮ No WHERE clause defaults to all records ▮ Copies all records and fields from a table in one schema to a table in another schema

10 Appendix B© copyright Janson Industries 201110 Modifying data ▮ Delete From table Where condition, allows you to delete records from a table ▮ Drop Table deletes the table and all data contained within ▮ Update allows you to modify field values

11 Appendix B© copyright Janson Industries 201111 Update ▮ UPDATE MYSCH01/INV SET PRICE = 17.95 WHERE ITEMNAM = ‘Hammer’ ▮ Changes all Hammer records ▮ Update is a very powerful command so:

12 Appendix B© copyright Janson Industries 201112 Views ▮ CREATE VIEW MYSCH01/CHEAP AS SELECT ITEMNAM, PRICE FROM MYSCH01/INV WHERE PRICE <.99 ▮ SELECT * FROM MYSCH01/CHEAP ▮ Shows item records that have a price less than 99 cents

13 Appendix B© copyright Janson Industries 201113 Indices ▮ CREATE INDEX MYSCH01/INVPRC ON MYSCH01/INV (PRICE) ▮ SELECT * FROM MYSCH01/INVPRC ▮ Shows item records in price order ▮ Using indices speeds up retrievals

14 Appendix B© copyright Janson Industries 201114 Managing SQL objects DROPSCHEMA or COLLECTION DROP VIEW DROP INDEX

15 Appendix B© copyright Janson Industries 201115 Special SQL commands ▮ Small problem with SQL and Java (and most programming languages): ▮ SQL returns more then one record/row at a time (called a result set) ▮ Most PL’s work on one record at a time ▮ Java solution: cursors and.next() method (see DB Access chapter for more info) Uh–Oh !

16 Appendix B© copyright Janson Industries 201116 Points to Remember ▮ SQL is standard across RDBMS ▮ Provides CRUD functions to a DBMS ▮ Update capability is very powerful


Download ppt "Appendix B© copyright Janson Industries 20111 SQL ▮ Explain basic SQL concepts ▮ Demonstrate SQL commands ▮ Results Sets."

Similar presentations


Ads by Google