sql and database management mis 171 – web technologies and innovation paul f. clay, ph.d
Post on 19-Dec-2015
217 views
TRANSCRIPT
SQL and Database SQL and Database ManagementManagement
MIS 171 – Web Technologies and Innovation MIS 171 – Web Technologies and Innovation
Paul F. Clay, Ph.D.Paul F. Clay, Ph.D.
DefinitionsDefinitions
• DataData– Facts, images, sound and videoFacts, images, sound and video
• InformationInformation– Data that has been processed so that it Data that has been processed so that it
can be interpreted and usedcan be interpreted and used
• MetadataMetadata– Data about dataData about data
3
Database SystemDatabase System
• The database system The database system consists of four major consists of four major components:components:– Database: Database:
• Collection of integrated Collection of integrated and shared data and shared data
– HardwareHardware• Processor: CPUProcessor: CPU• Memory: primary, Memory: primary,
secondary and tertiary secondary and tertiary – Software: Software:
• Database Management Database Management System (DBMS) System (DBMS)
• Application programsApplication programs– People: People:
• Administrators, Designers, Administrators, Designers, Developers, End UsersDevelopers, End Users
Database(Data andmetadata)
DBMS Software Process Queries Access data
Application Program
Users
4
Database System: DatabaseDatabase System: Database
• DatabaseDatabase• HardwareHardware• SoftwareSoftware• PeoplePeople
• An organized collection of An organized collection of logically-related persistent data logically-related persistent data
• A shared self-describing collection A shared self-describing collection of inter-related dataof inter-related data
• Implicit PropertiesImplicit Properties– Represents some aspect of the Represents some aspect of the
real world called the “mini real world called the “mini world” or the “universe of world” or the “universe of discourse”discourse”
– A logically related collection of A logically related collection of datadata
– Developed for a specific Developed for a specific purposepurpose
– Has “metadata,” i.e., Has “metadata,” i.e., repository of definitionsrepository of definitions
5
Database System: HardwareDatabase System: Hardware
• DatabaseDatabase• HardwareHardware• SoftwareSoftware• PeoplePeople
• Processor to support the Processor to support the execution of the database system execution of the database system software. software.
• StorageStorage– Primary:Primary: main memory/ main memory/
random access memory (RAM) random access memory (RAM) and cacheand cache
– Secondary:Secondary: Magnetic Disks Magnetic Disks – Tertiary:Tertiary: Tapes Tapes
6
Database System: SoftwareDatabase System: Software
• DBMS: Software used to define, DBMS: Software used to define, create, maintain, and provide create, maintain, and provide controlled access to the database controlled access to the database – Define:Define: Specify data types, Specify data types,
structures and constraints for the structures and constraints for the data to be storeddata to be stored
– Populate:Populate: Process of entering/ Process of entering/ storing the datastoring the data
– Manipulate:Manipulate: includes such includes such functions as querying to retrieve functions as querying to retrieve specific data, updating the specific data, updating the database to reflect changes, and database to reflect changes, and generating reports from the datagenerating reports from the data
– Control:Control: grant / restrict grant / restrict permissions, securitypermissions, security
• Examples of DBMS: Examples of DBMS: – Oracle 10g, IBM DB2, MS-SQL Oracle 10g, IBM DB2, MS-SQL
Server, MS-Access, My SQLServer, MS-Access, My SQL
• DatabaseDatabase• HardwareHardware• SoftwareSoftware• PeoplePeople
77
Database System: PeopleDatabase System: People
• Database Designer:Database Designer: – Design database structure, i.e., Design database structure, i.e.,
they are database architects they are database architects • Database Administrators: Database Administrators:
– Manage the DBMS use and ensure Manage the DBMS use and ensure that the database is functioning that the database is functioning properlyproperly
• Application programmers:Application programmers: – Responsible for writing application Responsible for writing application
programs that use the database programs that use the database typically in a language like C, Java typically in a language like C, Java etc.etc.
• End users:End users: – Interact with the system from Interact with the system from
online workstations or terminalsonline workstations or terminals
• DatabaseDatabase• HardwareHardware• SoftwareSoftware• PeoplePeople
88
Database Example: Table Database Example: Table CORPCORP
SYMBOL NAMESYMBOL NAME
-------------------- ------------------------------------------------ ----------------------------
INTC INTEL CORPINTC INTEL CORP
CSCO CISCO SYSTEMSCSCO CISCO SYSTEMS
MSFT MICROSOFT CPMSFT MICROSOFT CP
ORCL ORACLE CORPORCL ORACLE CORP
AMAT APPLIED MATLAMAT APPLIED MATL
JDSU JDS UNIPHASEJDSU JDS UNIPHASE
SUNW SUN MICROSYSSUNW SUN MICROSYS
BRCD BROCADE COMMSBRCD BROCADE COMMS
SIRI SIRIUS SAT RADISIRI SIRIUS SAT RADI
MCDTA MCDATA CL AMCDTA MCDATA CL A
DELL DELL INCDELL DELL INC
data
met
adat
a
99
Benefits of Database Benefits of Database Approach Approach
• The data can be sharedThe data can be shared– Sharing data is straightforward.Sharing data is straightforward.
• FS: Write program. Hard to share old data.FS: Write program. Hard to share old data.• DB: Existing data can easily be shared by many DB: Existing data can easily be shared by many
applications.applications.
• Redundancy can be reducedRedundancy can be reduced– Facts are recorded in one place in database.Facts are recorded in one place in database.
• FS: Write program. Hard to control.FS: Write program. Hard to control.• DB: Redundancy can be controlled.DB: Redundancy can be controlled.
• Inconsistency can be avoided (to some extent)Inconsistency can be avoided (to some extent)– Make sure Make sure SymbolSymbol of each company is valid. of each company is valid.– Make sure each company Make sure each company name name is not stored more than is not stored more than
once.once.• FS: Write program.FS: Write program.• DB: DBMS can enforce some types of “DB: DBMS can enforce some types of “integrity.integrity.””
1010
Benefits of Database Benefits of Database Approach [2] Approach [2]
• Transaction support can be providedTransaction support can be provided– Allow multiple users to run the program at the same Allow multiple users to run the program at the same
time.time.• FS: Write programs, maybe using locks.FS: Write programs, maybe using locks.• DB: DBMS supports DB: DBMS supports transaction managementtransaction management..
• Security can be enforcedSecurity can be enforced– Authorize each user controlled access (e.g., insert, Authorize each user controlled access (e.g., insert,
update).update).• FS: Write programs, maybe using passwords.FS: Write programs, maybe using passwords.• DB: DBMS enforces DB: DBMS enforces securitysecurity..
• Standards can be enforcedStandards can be enforced– Standardize the data representation across systems?Standardize the data representation across systems?
• FS: All programs must agree on the data representation.FS: All programs must agree on the data representation.• DB: The DBA can ensure that all applicable standards are DB: The DBA can ensure that all applicable standards are
observed in the representation of data.observed in the representation of data.
1111
Evolution of Database Evolution of Database SystemsSystems
• Pre-1960sPre-1960s– 1945: Magnetic tape developed1945: Magnetic tape developed– 1959: IBM introduced the RAMAC (1959: IBM introduced the RAMAC (RRandom andom AAccess ccess MMethod of ethod of AAccounting And ccounting And
CControl) systemontrol) system• 1960s1960s
– Information Management System (IMS) developed by IBMInformation Management System (IMS) developed by IBM– SABRE developed by IBM and American AirlinesSABRE developed by IBM and American Airlines
• 1970s1970s– Relational model developed by Ted CoddRelational model developed by Ted Codd– ER diagram introduced by ChenER diagram introduced by Chen
• 1980s1980s– DBMS developed for personal computers (DBASE, PARADOX)DBMS developed for personal computers (DBASE, PARADOX)– Preliminary SQL standard publishedPreliminary SQL standard published
• 1990s 1990s – Parallel processorsParallel processors– OODBOODB– Standards for data query and exchange (SQL2)Standards for data query and exchange (SQL2)
• 50 disks, 2’• 5 MB• $10k/MB
12
OverviewOverview
• SQL SQL – Structured Query LanguageStructured Query Language– High level declarative language for relational High level declarative language for relational
databasedatabase
• De facto standard in the database worldDe facto standard in the database world• Is now anIs now an official official standard too, accepted bystandard too, accepted by
– American National Standards Institute (ANSI)American National Standards Institute (ANSI)– International Organization for Standardization International Organization for Standardization
(ISO)(ISO)
• The first standard (1986): SQL/86The first standard (1986): SQL/86• SQL2 (SQL/92) is the most popularly in use SQL2 (SQL/92) is the most popularly in use
todaytoday
13
SQLSQL
• DDL DDL – Define the databaseDefine the database– CREATE, ALTER and DROP a TABLE, VIEW or INDEXCREATE, ALTER and DROP a TABLE, VIEW or INDEX
• DMLDML– Manipulate the data in an existing databaseManipulate the data in an existing database– INSERT, UPDATE, DELETEINSERT, UPDATE, DELETE– SELECT, i.e., querySELECT, i.e., query
• DCLDCL– Control user access to an existing databaseControl user access to an existing database– GRANT and REVOKEGRANT and REVOKE
14
SQL- querySQL- query
SELECT <columns>SELECT <columns>
FROM <table>FROM <table>
[WHERE <condition>][WHERE <condition>]
[GROUP BY <columns>][GROUP BY <columns>]
[HAVING <condition>][HAVING <condition>]
[ORDER BY <column>];[ORDER BY <column>];
What is the first and last What is the first and last name of every student name of every student who has a GPA greater who has a GPA greater than 3.5?than 3.5?
SELECT SELECT F_Name, L_NameF_Name, L_Name
FROM FROM StudentStudent
WHERE WHERE GPA>3.5GPA>3.5
14
1515
SID L_Name L_Name GPA
116486323 Borgnini Guido 3.69
139152051 Di Giorgio Christopher 3.13
155264660 Henselmeier Carrie 2.78
161153753 Krefetz Brett 3.7
191040015 Mc Hugh Michael 3.28
169474871 Mc Murray Joe 3.46
178626939 Oizumi Nicolas 2.33
140200720 Raczkowski Matthew 3.61
109020026 Varadarajan Preethi 2.42
109687528 Wilds Christopher 3.19
123282854 Wiley Nora 3.38
110620555 Yuan Dawei 2.13
SELECT SELECT F_Name, L_NameF_Name, L_Name
FROM FROM StudentStudent
WHERE WHERE GPA>3.5GPA>3.5
L_Name L_Name
Krefetz Brett
Borgnini Guido
Raczkowski Matthew