ielm 511: information system design
DESCRIPTION
IELM 511: Information System design. Introduction. Part 1. ISD for well structured data – relational and other DBMS. Info storage (modeling, normalization) Info retrieval (Relational algebra, Calculus, SQL) DB integrated API’s. ISD for systems with non-uniformly structured data. - PowerPoint PPT PresentationTRANSCRIPT
IELM 511: Information System design
Introduction
Part 1. ISD for well structured data – relational and other DBMS
ISD for systems with non-uniformly structured data
Part III: (one out of)
Basics of web-based IS (www, web2.0, …)Markup’s, HTML, XMLDesign tools for Info Sys: UML
API’s for mobile appsSecurity, CryptographyIS product lifecyclesAlgorithm analysis, P, NP, NPC
Info storage (modeling, normalization)Info retrieval (Relational algebra, Calculus, SQL)DB integrated API’s
Agenda
Structured Query Language (SQL)
DB API’s
1
n
1
n
mn
1
n
1 n
m
n
1
n
1
n
mn
1
n
1 n
m
n
Recall our Bank DB design
BRANCH( b_name, city, assets)
CUSTOMER( cssn, c_name, street, city, banker, banker_type)
LOAN( l_no, amount, br_name)
PAYMENT( l_no, pay_no, date, amount)
EMPLOYEE( e_ssn, e-name, tel, start_date, mgr_ssn)
ACCOUNT( ac_no, balance)
SACCOUNT( ac_no, int_rate)
CACCOUNT( ac_no, od_amt)
BORROWS( cust_ssn, loan_num)
DEPOSIT( c_ssn, ac_num, access_date)
DEPENDENT( emp_ssn, dep_name)
Background: Structured Query Language
Basics of SQL:
A DataBase Management System is an IT system
Core requirements: - A structured way to store the definition of data [why ?] DDL - Manipulation of data [obviously!] DML
SQL: a combined DDL+DML
SQL as a DDL
A critical element of any design is to store the definitions of its components.
In DB design, we deal with tables, using table names, attribute names etc.Each of these terms should have unambiguous syntax and semantics.
A systematic way to specify and store these meta-data is by the use of aData Definition Language
The information about the data is stored in a Data Dictionary
SQL provides a unified DDL + a Data Manipulation Language (DML).
SQL as a DDL: create command
To create a new database:
create database my_database;
To create a new table:
create table my_table (attribute_name attribute_type constraint,….,constraint, …
);
To create an index on a table:
create index my_index on my_table( attribute);
A DB stores one or more tablesand one or more indexes
A table stores data
An index is a special filefor faster DB look-up,when searching the specifiedtable for some data usingthe specified attribute.
SQL as a DDL: create command examples
create database bank;
create table loan ( l_no char(10), amount double, br_name char(30) references branch(b_name), primary key (loan_number));
BORROWS( cust_ssn, loan_num)
create table borrows ( cust_ssn char(11), loan_num char(10), primary key (cust_ssn, loan_num), constraint borrows_c1 foreign key cust_ssn references customer( cssn), constraint borrows_c2 foreign key loan_num references loan( l_no));
LOAN( l_no, amount, br_name)
Note on metadata: system catalogs
Metadata = data about data.
DBMS manages a ‘data dictionary’ sometimes called ‘system catalog’ with
- When was the DB and each table created/modified - Name of each attribute, its data type, and comments describing it, - List of all users who can access the DB and their passwords, - Which user can do what (read/add/update/delete/authorize) to the data.
System catalog itself is stored in a table, and users can see (if theyhave authority) the data in it.
SQL as a DML: insert, drop commands
To add one row into a table:
insert into branch values( “Downtown”, “Brooklyn”, 9000000);
insert into loan values( “L17”, 1000, “Downtown”);
To remove an entire table from the DB:
drop table branch;
Sequence in which you execute ‘insert’ matters !This insert will fail unless table ‘branch’ has a row with ‘Downtown’
Note: this ‘drop’ command will fail if, e.g. there is data in table ‘loan’ [why?]
Note: char( ), date, datetime types: data must be “quoted” integer, single, double (number data types) are not quoted.
SQL as a DML: select command
To get some data from a ( set of ) table (s):
select attribute1, …, attribute_nfrom table_1, …, table_mwhere selection_or_join_condition1, …, selection_or_join_condition_rgroup by attribute_ihaving aggregate_function( attribute_j, … )order by attribute_kO
ptio
nal
Req
uire
d
SQL as a DML: select command
select customer, loan_nofrom borrows;
customer loan_no
111-12-0000 L17
222-12-0000 L23
333-12-0000 L15
444-00-0000 L93
666-12-0000 L17
111-12-0000 L11
999-12-0000 L17
777-12-0000 L16
To get some data from a ( set of ) table (s)
select customer as “customer ssn”from borrows; customer ssn
111-12-0000
222-12-0000
333-12-0000
444-00-0000
666-12-0000
111-12-0000
999-12-0000
777-12-0000
select * from borrows;
Notes:* is a wildcardas: gives alias name to attribute
select distinct loan_nofrom borrows;
loan_no
L17
L23
L15
L93
L11
L16
SQL select: row filters
select distinct branch_namefrom loanwhere amount > 1200
Example: Find the names of all branches that have given loans larger than 1200
branch_name
Redwood
Pennyridge
Note: all operations in ‘where’are applied one row at a time
loan_number amount branch_name
L17 1000 Downtown
L23 2000 Redwood
L15 1500 Pennyridge
L93 500 Mianus
L11 900 Round Hill
L16 1300 Pennyridge
LOAN
SQL select: joins
select customer, loan.*from borrows, loanwhere loan_no = loan_number and amount > 1200
-condition for join of loan, borrows
selection condition
Example: Find the customer ssn, loan no, amount and branch name for all loans > 1200
customer loan_number amount branch_name
222-12-0000 L23 2000 Redwood
333-12-0000 L15 1500 Pennyridge
777-12-0000 L16 1300 Pennyridge
WHERE clause:multiple -conditions and, or, notcomparing cell values: >, =, !=, <, etc.
BORROWS
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
LOAN
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
SQL select: joins with table and column aliases
select E.e_name as worker, M.e_name as bossfrom employee as E, employee as Mwhere E.mgr_ssn = M.e_ssn
Note:
E, M are aliases (copies) of employee table
Example: Find the names of employees and their manager.
worker boss
Jones Adams
Smith Jones
Lee Jones
Turner Adams
Jones Chan
Chan Black
Adams Black
Black null
E = M
888-99-9999Mar-199587621Jones987-65-4321
777-77-7777Feb-198087654Chan888-99-9999
99111
77777
55555
54321
54321
12345
tel
Jan-1980
Feb-1990
Aug-2002
Mar-1998
Mar-1998
Nov-2005
start_date
nullBlack777-77-7777
321-32-4321
555-66-8888
123-45-6789
333-11-4444
111-22-3333
e_ssn
777-77-7777Adams
321-32-4321Turner
111-22-3333Lee
111-22-3333Smith
321-32-4321Jones
mgr_ssne_name
888-99-9999Mar-199587621Jones987-65-4321
777-77-7777Feb-198087654Chan888-99-9999
99111
77777
55555
54321
54321
12345
tel
Jan-1980
Feb-1990
Aug-2002
Mar-1998
Mar-1998
Nov-2005
start_date
nullBlack777-77-7777
321-32-4321
555-66-8888
123-45-6789
333-11-4444
111-22-3333
e_ssn
777-77-7777Adams
321-32-4321Turner
111-22-3333Lee
111-22-3333Smith
321-32-4321Jones
mgr_ssne_name
SQL select: nested queries, in
select c_ssnfrom depositwhere c_ssn in ( select customer
from borrows)Notes:‘in’ performs a set membership test
Example: Find ssn of customers who have both deposit and loan
c_ssn
222-12-0000
333-12-0000
111-12-0000
BORROWS
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_noDEPOSIT
Mar 1, 09A217111-12-0000
Feb 25, 09A101000-12-0000
888-12-0000
555-00-0000
333-12-0000
222-12-0000
888-12-0000
c_ssn
Mar 1, 98A201
Mar 10, 09A305
Feb 28, 09A102
Feb 1, 09A215
Jan 1, 09A101
accessDateac_num
Mar 1, 09A217111-12-0000
Feb 25, 09A101000-12-0000
888-12-0000
555-00-0000
333-12-0000
222-12-0000
888-12-0000
c_ssn
Mar 1, 98A201
Mar 10, 09A305
Feb 28, 09A102
Feb 1, 09A215
Jan 1, 09A101
accessDateac_num
SQL select: nested queries, in
select c_ssnfrom depositwhere c_ssn not in ( select customer
from borrows)
Notes:‘not in’ is true if ‘in’ is false.
Example: Find ssn of customers who have a deposit but no loan
c_ssn
888-12-0000
555-00-0000
888-12-0000
000-12-0000
BORROWS
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_noDEPOSIT
Mar 1, 09A217111-12-0000
Feb 25, 09A101000-12-0000
888-12-0000
555-00-0000
333-12-0000
222-12-0000
888-12-0000
c_ssn
Mar 1, 98A201
Mar 10, 09A305
Feb 28, 09A102
Feb 1, 09A215
Jan 1, 09A101
accessDateac_num
Mar 1, 09A217111-12-0000
Feb 25, 09A101000-12-0000
888-12-0000
555-00-0000
333-12-0000
222-12-0000
888-12-0000
c_ssn
Mar 1, 98A201
Mar 10, 09A305
Feb 28, 09A102
Feb 1, 09A215
Jan 1, 09A101
accessDateac_num
SQL select: nested, correlated queries, exists
select branch_namefrom branchwhere not exists (select *
from loanwhere branch.branch_name = loan.branch_name)
1. Correlated: ‘where’ clause of inner query refers to outer query2. ‘exists’ is true is there is >= 1 row in evaluating inner query; ‘not exists’ is true is ‘exists’ is false
Existential qualifier (a generalization of ‘in’)
Example: Find the names of branches that have given no loan
LOAN
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
BRANCH
300000BenningtonPownal
3700000RyeNorth Town
7100000BrooklynBrighton
Round Hill
Mianus
Pennyridge
Redwood
Downtown
branch_name
8000000Horseneck
400000Horseneck
1700000Horseneck
2100000Palo Alto
9000000Brooklyn
assetscity
300000BenningtonPownal
3700000RyeNorth Town
7100000BrooklynBrighton
Round Hill
Mianus
Pennyridge
Redwood
Downtown
branch_name
8000000Horseneck
400000Horseneck
1700000Horseneck
2100000Palo Alto
9000000Brooklyn
assetscity
SQL select: arithmetic operations on columns
select branch_name, assets*0.000001 as “assets (m)”from branch
Notes: arithmetic ops can be used in SELECT, WHERE, HAVING
Report the branch name and assets in units of millions BRANCH
300000BenningtonPownal
3700000RyeNorth Town
7100000BrooklynBrighton
Round Hill
Mianus
Pennyridge
Redwood
Downtown
branch_name
8000000Horseneck
400000Horseneck
1700000Horseneck
2100000Palo Alto
9000000Brooklyn
assetscity
300000BenningtonPownal
3700000RyeNorth Town
7100000BrooklynBrighton
Round Hill
Mianus
Pennyridge
Redwood
Downtown
branch_name
8000000Horseneck
400000Horseneck
1700000Horseneck
2100000Palo Alto
9000000Brooklyn
assetscity
branch_name assets (m)
Downtown 9.0
Redwood 2.1
Pennyridge 1.7
Mianus 0.4
Round Hill 8.0
Pownal 0.3
North Town 3.7
Brighton 7.1
select branch_name, avg( amount) as Avg, max( amount) as Max, count( branch_name) as no_loansfrom loangroup by branch_nameorder by no_loans desc
SQL select: group by, group-wise aggregation functions
1. Aggregating functions: avg, max, min, sum, count2. avg/max return average/max for each group
Example: Report the average, maximum amount, and number of loans by branch
branch_name Avg Max no_loans
Pennyridge 1400 1500 2
Downtown 1000 1000 1
Redwood 2000 2000 1
Mianus 500 500 1
Round Hill 900 900 1
LOAN
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
SQL select: group by, having
select loan_number, amount, count( loan_number) as no_debtorsfrom loan, borrowswhere loan_number = loan_no and amount <= 1500group by loan_numberhaving count(loan_number) >= 2
‘having’ conditions are only applied to data after rows have been grouped‘order by’ used with ‘group by’ will be applied to groups.
‘having’ is used to screen out groups from the output
Example: Report the small loans (<= 1500) held by 2 or more people.
BORROWS
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_noLOAN
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
loan_number amount no_debtors
L17 1000 3
SQL select: date functions
select c_ssnfrom depositwhere datediff( yy, accessDate, getdate( ) ) > 5
datediff units: yy (years), …, ns (nano-seconds)
SQL provides special functions to handle dates, times and strings
c_ssn ac_num accessDate
888-12-0000 A201 Mar 1, 98
DEPOSIT
Mar 1, 09A217111-12-0000
Feb 25, 09A101000-12-0000
888-12-0000
555-00-0000
333-12-0000
222-12-0000
888-12-0000
c_ssn
Mar 1, 98A201
Mar 10, 09A305
Feb 28, 09A102
Feb 1, 09A215
Jan 1, 09A101
accessDateac_num
Mar 1, 09A217111-12-0000
Feb 25, 09A101000-12-0000
888-12-0000
555-00-0000
333-12-0000
222-12-0000
888-12-0000
c_ssn
Mar 1, 98A201
Mar 10, 09A305
Feb 28, 09A102
Feb 1, 09A215
Jan 1, 09A101
accessDateac_num
Example: report those customers who have been inactive for over 5 years
SQL select: string functions
select ssn, name, street, cityfrom customerwhere name LIKE ‘J%’ or street LIKE ‘[^mnp]%’ or city LIKE ‘%[ ]%’
Wildcards:% zero or more chars[asd] match one char out of list [asd][^asd] matches any one char except a, s, d.
It is often useful to use wild-cards for string matching
ssn name street city
111-12-0000 Jones Main Harrison
777-12-0000 Adams Spring Pittsfield
888-12-0000 Johnson Alma Palo Alto
999-12-0000 Brooks Senator Brooklyn
CUSTOMER
DO888-99-9999StamfordPutnamTurner555-12-0000
LO333-11-4444PrincetonNassauWilliams666-12-0000
LO123-45-6789PittsfieldSpringAdams777-12-0000
DO888-99-9999Palo AltoAlmaJohnson888-12-0000
LO123-45-6789BrooklynSenatorBrooks999-12-0000
Pittsfield
Rye
Harrison
Rye
Harrison
city
Park
North
Main
North
Main
street
888-99-9999
333-11-4444
321-32-4321
321-32-4321
321-32-4321
banker
DOLindsay000-12-0000
444-12-0000
333-12-0000
222-12-0000
111-12-0000
ssn
LOCurry
CRMHayes
CRMSmith
CRMJones
b_typename
DO888-99-9999StamfordPutnamTurner555-12-0000
LO333-11-4444PrincetonNassauWilliams666-12-0000
LO123-45-6789PittsfieldSpringAdams777-12-0000
DO888-99-9999Palo AltoAlmaJohnson888-12-0000
LO123-45-6789BrooklynSenatorBrooks999-12-0000
Pittsfield
Rye
Harrison
Rye
Harrison
city
Park
North
Main
North
Main
street
888-99-9999
333-11-4444
321-32-4321
321-32-4321
321-32-4321
banker
DOLindsay000-12-0000
444-12-0000
333-12-0000
222-12-0000
111-12-0000
ssn
LOCurry
CRMHayes
CRMSmith
CRMJones
b_typename
SQL as a DML: update command…
update loanset amount = amount - 200where loan_number = ( select loan_no
from borrows, customerwhere customer = ssn and name = ‘Jones’ )
To modify an entry in a cell
LOAN
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
Pennyridge1300L16
Round Hill900L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown1000L17
branch_nameamountloan_number
BORROWS
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
CUSTOMER
DO888-99-9999StamfordPutnamTurner555-12-0000
LO333-11-4444PrincetonNassauWilliams666-12-0000
LO123-45-6789PittsfieldSpringAdams777-12-0000
DO888-99-9999Palo AltoAlmaJohnson888-12-0000
LO123-45-6789BrooklynSenatorBrooks999-12-0000
Pittsfield
Rye
Harrison
Rye
Harrison
city
Park
North
Main
North
Main
street
888-99-9999
333-11-4444
321-32-4321
321-32-4321
321-32-4321
banker
DOLindsay000-12-0000
444-12-0000
333-12-0000
222-12-0000
111-12-0000
ssn
LOCurry
CRMHayes
CRMSmith
CRMJones
b_typename
DO888-99-9999StamfordPutnamTurner555-12-0000
LO333-11-4444PrincetonNassauWilliams666-12-0000
LO123-45-6789PittsfieldSpringAdams777-12-0000
DO888-99-9999Palo AltoAlmaJohnson888-12-0000
LO123-45-6789BrooklynSenatorBrooks999-12-0000
Pittsfield
Rye
Harrison
Rye
Harrison
city
Park
North
Main
North
Main
street
888-99-9999
333-11-4444
321-32-4321
321-32-4321
321-32-4321
banker
DOLindsay000-12-0000
444-12-0000
333-12-0000
222-12-0000
111-12-0000
ssn
LOCurry
CRMHayes
CRMSmith
CRMJones
b_typename
LOAN
Pennyridge1300L16
Round Hill700L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown800L17
branch_nameamountloan_number
Pennyridge1300L16
Round Hill700L11
Mianus500L93
Pennyridge1500L15
Redwood2000L23
Downtown800L17
branch_nameamountloan_number
select * from loan
SQL as a DML: delete command…
delete from loan
To delete a row from a table
BORROWS
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
L17999-12-0000
L11111-12-0000
L16777-12-0000
666-12-0000
444-00-0000
333-12-0000
222-12-0000
111-12-0000
customer
L17
L93
L15
L23
L17
loan_no
CUSTOMER
DO888-99-9999StamfordPutnamTurner555-12-0000
LO333-11-4444PrincetonNassauWilliams666-12-0000
LO123-45-6789PittsfieldSpringAdams777-12-0000
DO888-99-9999Palo AltoAlmaJohnson888-12-0000
LO123-45-6789BrooklynSenatorBrooks999-12-0000
Pittsfield
Rye
Harrison
Rye
Harrison
city
Park
North
Main
North
Main
street
888-99-9999
333-11-4444
321-32-4321
321-32-4321
321-32-4321
banker
DOLindsay000-12-0000
444-12-0000
333-12-0000
222-12-0000
111-12-0000
ssn
LOCurry
CRMHayes
CRMSmith
CRMJones
b_typename
DO888-99-9999StamfordPutnamTurner555-12-0000
LO333-11-4444PrincetonNassauWilliams666-12-0000
LO123-45-6789PittsfieldSpringAdams777-12-0000
DO888-99-9999Palo AltoAlmaJohnson888-12-0000
LO123-45-6789BrooklynSenatorBrooks999-12-0000
Pittsfield
Rye
Harrison
Rye
Harrison
city
Park
North
Main
North
Main
street
888-99-9999
333-11-4444
321-32-4321
321-32-4321
321-32-4321
banker
DOLindsay000-12-0000
444-12-0000
333-12-0000
222-12-0000
111-12-0000
ssn
LOCurry
CRMHayes
CRMSmith
CRMJones
b_typename
all rows of loan table deleted
delete from customerwhere name = ‘Jones’
request to delete row of customer tablewith name = ‘Jones’[will it succeed ?]
Views in SQL
A view is a virtual table defined on a given Database:
The columns of the view are either(i) columns from some (actual or virtual) table of the DB
or (ii) columns that are computed (from other columns)
Main uses of a view:
- Security (selective display of information to different users)
- Ease-of-use-- Explicit display of derived attributes-- Explicit display of related information from different tables-- Intermediate table can be used to simplify SQL query
Create a view showing the names of employees, their ssn, telephone number,their manager's name, and how many years they have worked in the bank.
create view bank_employee as select e.e_ssn as ssn, e.e-name as name, e.tel as phone, m.e-name as manager, datediff( yy, start_date, getdate( )) as n_years from EMPLOYEE as e, EMPLOYEE as m where e.mgr_ssn = m.e_ssn
select * from bank_employee
Views in SQL..
ssn name phone manager n_years
111-22-3333 Jones 12345 Adams 15
333-11-4444 Smith 54321 Jones 12
123-45-6789 Lee 54321 Jones 12
555-66-8888 Turner 55555 Adams 8
987-65-4321 Jones 87621 Chan 15
888-99-9999 Chan 87654 Black 30
321-32-4321 Adams 77777 Black 30
777-77-7777 Black 99111 null 30
View definition is persistent – once you define it, the definition stayspermanently in the DB until you drop the view.
Operations on Views
You can use the view in any SQL query just the same as any other table, BUT(1) You cannot modify the value of a computed attribute(2) If an update/delete command is execute, the underlying data in the referenced table of the view is updated/deleted. [this can cause unexpected changes in your DB]
The DBMS only computes the data in a view when it is referencedin a SQL command (e.g. in a select … command)no physical table is stored in the stored memory corresponding to the view.
SQL language has some other useful commands and operators [e.g. see here]
In addition, most DBMS will provide many non-standard operators and servicesto facilitate information system deployment and administration.
DBMSs can handle very large amount of data, and process queries very fast.IBM’s DB2 can handle over 6m transactions per min (tpm); Oracle 10g, over 4m tpm
To speed up queries, you can use indexes.
Common DBMSs: IBM DB2, Oracle 10g, Microsoft SQL Server, Sybase, MySQL.all support SQL.
Concluding remarks on SQL
Most people use DBs, but always through some computer program interface (API).
Most DBMSs will provide program ‘libraries’ (a collection of a set of compliedfunctions) with functions to: - Connect to the DBMS - Select a DB - Send a SQL command, and receive the response in some standard data structure.
Each DBMS provides one library for each programming language.
On Windows™ (and several other) systems, these libraries are called ODBC
Database API’s
DBMSDB
your codeodbc funcmore code
odbc (DLL)
Client App
SQL query
Response
Bank tables..
BRANCH
branch_name city assets
Downtown Brooklyn 9000000
Redwood Palo Alto 2100000
Pennyridge Horseneck 1700000
Mianus Horseneck 400000
Round Hill Horseneck 8000000
Pownal Bennington 300000
North Town Rye 3700000
Brighton Brooklyn 7100000
EMPLOYEE
e_ssn e_name tel start_date mgr_ssn
111-22-3333 Jones 12345 Nov-2005 321-32-4321
333-11-4444 Smith 54321 Mar-1998 111-22-3333
123-45-6789 Lee 54321 Mar-1998 111-22-3333
555-66-8888 Turner 55555 Aug-2002 321-32-4321
987-65-4321 Jones 87621 Mar-1995 888-99-9999
888-99-9999 Chan 87654 Feb-1980 777-77-7777
321-32-4321 Adams 77777 Feb-1990 777-77-7777
777-77-7777 Black 99111 Jan-1980 null
CUSTOMER
ssn name street city banker b_type
111-12-0000 Jones Main Harrison 321-32-4321 CRM
222-12-0000 Smith North Rye 321-32-4321 CRM
333-12-0000 Hayes Main Harrison 321-32-4321 CRM
444-12-0000 Curry North Rye 333-11-4444 LO
555-12-0000 Turner Putnam Stamford 888-99-9999 DO
666-12-0000 Williams Nassau Princeton 333-11-4444 LO
777-12-0000 Adams Spring Pittsfield 123-45-6789 LO
888-12-0000 Johnson Alma Palo Alto 888-99-9999 DO
999-12-0000 Brooks Senator Brooklyn 123-45-6789 LO
000-12-0000 Lindsay Park Pittsfield 888-99-9999 DO
DEPOSITc_ssn ac_num accessDate
888-12-0000 A101 Jan 1, 09
222-12-0000 A215 Feb 1, 09
333-12-0000 A102 Feb 28, 09
555-00-0000 A305 Mar 10, 09
888-12-0000 A201 Mar 1, 98
111-12-0000 A217 Mar 1, 09
000-12-0000 A101 Feb 25, 09
BORROWScustomer loan_no
111-12-0000 L17
222-12-0000 L23
333-12-0000 L15
444-00-0000 L93
666-12-0000 L17
111-12-0000 L11
999-12-0000 L17
777-12-0000 L16
LOANloan_number amount branch_name
L17 1000 Downtown
L23 2000 Redwood
L15 1500 Pennyridge
L93 500 Mianus
L11 900 Round Hill
L16 1300 Pennyridge
Not all tables of our normalizeddesign are shown; please createand populate for practice.
References and Further Reading
Silberschatz, Korth, Sudarshan, Database Systems Concepts, McGraw Hill
Next: IS for non-structured data