sql overview
DESCRIPTION
SQL Overview. Introduction to SQL for the MultiValue Developer. Why are we here?. Many MultiValue developers now are working with the various relational databases We want to look at common commands and data structures for SQL databases We want to see how they relate to the MultiValue. eris. - PowerPoint PPT PresentationTRANSCRIPT
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
SQL Overview
Introduction to SQL for the MultiValue Developer
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Why are we here?
• Many MultiValue developers now are working with the various relational databases
• We want to look at common commands and data structures for SQL databases
• We want to see how they relate to the MultiValue
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
eris
• Database to Web integration since 1992• Customers with up to $2 Billion in annual revenue• Clients throughout North America• Education, Medical, Manufacturing, EDI,
Distribution, Sales Force Automation, Help Desk, and Reporting Systems
• e-Commerce and database product development, e.g., WebWizard, DataReady, mv://e-Store
• Los Angeles and Chicago offices
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Agenda
• About eris
• SQL Overview– Basics– Reporting– Database maintenance
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
What is SQL?
• Standard Query Language
• Used to communicate with the database– Get data– Maintain data– Create data
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Standard SQL?
• Not really
• Similar related languages (think Latin)– You need to understand the dialect– Be able to compare what yours has vs others
• Hmm…Think MultiValue
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Basic parts of SQL
• Data Definition Language (DDL)
• Database Manipulation Language (DML)
• Database Control Language (DCL)
• Database Stored Procedure Language (DSPL)
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Data Definition Language (DDL)
• Defines the database environment• Varies most among the various SQL flavors• Covers
– Database– Design Structures– Related System Tables– Metadata
• Schemas• Catalogs• Stored Procedures• Other structural elements
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Database Manipulation Language (DML)
• Reasonably standardized.
• We'll look at DML later on
• Problems arise not in what they offer but what they might not have– Types of joins– Sub-queries
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Database Control Language (DCL)
• How to maintain and configure the database
• Permission, roles, and referential integrity– Grant– Check– Constraint– Primary Key– Foreign Key
• Fairly dissimilar among the various flavors
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Database Stored Procedure Language (DSPL)
• All the previous variations compound when you get to this section
• Triggers
• Event handler
• Stored procedures
• Can barely compare– Oracle's PL/SQL – SQL Server's Transact SQL – DB2's Stored Procedures
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Reporting – Which SQL?
• Microsoft SQL Server
• mySQL
• Oracle
• DB2
• SQLite
• SQLAnywhere
• MultiValue, such as in uniVerse/UniData
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
What does a table look like?
city state high low
Las Vegas Nevada 115 90
Pasadena California 88 57
Pasadena Texas 92 81
Santa Monica California 77 67
Weather
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Lingo
• Row– Record
• Column– Attribute / Field
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
How do I list?
• Select
• select high, low from Weather where city like “%Pasa%”;
• select * from Weather where city = “California”;
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Selecting Data
• “select” is comparable to “LIST”
• Syntax:select column1 [,column2,etc or * for all]
from tablename[where condition] ;
• Compare with – LIST "tablename" "column1" "column2" WITH "condition"
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Roster database
first last id age city
Eric Edwards 2101 17 San Diego
John Johnson 1801 17 Pasadena
Sam Joliet 1314 17 Pasadena
Mary Jones 1342 16 Altadena
Eric Taylor 2412 16 Pasadena
Joseph Tyler 1442 17 Pasadena
Janice Williams 1446 16 Pasadena
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Sample queries
• select first, last, city from roster;
• select last, city, age from roster where age > 30;
• select first, last, city, state from roster where first like 'J%';
• select * from roster;
• select first, last, from roster where last like '%s';
• select first, last, age from roster where last like '%on%';
• select * from roster where first = 'Eric';
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Sample operators in Joins, Where and Having
• And, Or, Not – itemWidth > 11 and itemHeight < 14 – not (region = "E" or sales < quota)
• Is Null, Is Not Null– Nulls occur when no data value has been entered into a
field. Different from MultiValue
• Between– a shorthand way to refer to a range– totalSales between 1500 and 1800
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
More operators
• In, Not In - allows table lookups– vehicleType in ("sedan", "roadster", "2-door") – sportPlayed not in ("tennis","squash", "badminton",
"raquetball")
• Like– one of the most powerful for searches within a text or
varchar field– Think “…” or “[“ and “]” in MultiValue– Supports text search patterns which work like but not
identically the same in syntax as regular expressions from Unix and XML
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Like, Even More Operators
• "%" is any length (think "*" in DOS)
• "_" is a single character (think "?" in DOS)
• [] lists valid characters at the point:[mp]a[nt] can be map, mat, pan, pat[0-9] means a numeric character
• [^] lists excluded characters
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Inner Joins
• This is what makes SQL "relational“
• It joins tables
• Similar to translates in MultiValue
• Syntax:
select list-of-columnsfrom tablename1,tablename2where search-condition(s) ;
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Imagine an Inner Join
• customers table– customer_id– firstname– lastname– address– city– state – zip
• sales table– sale_id– cust_id– date – Item– price
select customers.firstname, customers.lastname, sales.item
from customers, sales
where customers.customer_id = sales.cust_id;
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
No need for a new dictionary element
• The columns have the table name in front
• A period separates the table name from the column name– This is opional but is very recommended. It is
required if the name column names are the same between the two tables.
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Alternate Syntax
select customers.firstname, customers.lastname, sales.item
from customers, sales
where customers.customer_id = sales.cust_id;
select customers.firstname, customers.lastname, sales.item
from customersinner join sales
on customers.customer_id = sales.cust_id;
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Database Maintenance
• Creating tables
• Adding records
• Editing records
• Deleting records
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Creating tables
• Analogous to CREATE-FILE / CREATE.FILE• Syntax:
create table tablename(column1 datatype, …) ;
• Table and Column names– must start with a letter– can be followed by letters, numbers, or underscores– not to exceed a total of 30 characters in length– Do not use any SQL reserved keywords
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Common Data types
char(size) Fixed-length character string. Size is specified in parenthesis. Max 255 bytes.
varchar(size) Variable-length character string. Max size is specified in parenthesis.
number(size) Number value with a max number of column digits specified in parenthesis.
date Date value
number(size,d) Number value with a maximum number of digits of "size" total, with a maximum number of "d" digits to the right of the decimal.
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Add records - Insert
• Syntax:
insert into tablename (first_column, ... ,last_column) values (‘first_value’, ... ,’last_value’);
• Strings need single-quotes!
• Example:insert into customers (first, last, age, address, city, state) values ('Joe', 'Johnson', 21, '199 Los Robles', 'Pasadena', 'California');
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Updating Records - Update and where
• Syntax:
update tablenameset first_column = new_value[,next_column = newvalue2 …]
where condition [and|or condition2 …];
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Examples
• update phone_bookset area_code = 323where prefix = 213;
• update phone_bookset prefix=555, suffix=9292where last_name = 'Jones'and first_name = 'John' ;
• update employeeset age = age+1where first_name='Mary' and last_name='Williams';
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Deleting records
• Syntax:
delete from tablenamewhere condition[and|or condition2 …];
• Warning! if you leave off the where clause, all records will be deleted!
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Bottom Line
• SQL has the very same intent, functionality, and general purpose across database vendors - users have had to get used to working in dialects.
• SQL interoperability is a problem.
• It provides the Rosetta Stone of a standard, common syntax for data interchange not just between relational databases; but also structured data in general.
eagle rock information systems199 So Los Robles, Suite 860, Pasadena, CA 91101 USA
626-535-9658www.eriscorp.com
Contact us
Main Office: 199 S. Los Robles Ave, Suite 860
Pasadena, CA 91101
Tel: (626) 535-9658 Fax: (626) 628-3229
www.eriscorp.com
info @ eriscorp.com