200 likes | 355 Views
Relational Databases. Stephen Fulwider COT 4810 4 March 2008. DBMS. “software designed to assist in maintaining and utilizing large collections of data.” (Ramakrishnan) VLDB (>1TB Storage) Google Yahoo! NSA/FBI/CIA. Alternate: File Systems.
E N D
Relational Databases Stephen Fulwider COT 4810 4 March 2008
DBMS • “software designed to assist in maintaining and utilizing large collections of data.” (Ramakrishnan) • VLDB (>1TB Storage) • Google • Yahoo! • NSA/FBI/CIA
Alternate: File Systems • Obvious drawback – custom code required per app • Special code needed to answer each question • OS-Dependent • If data write fails, what happens to the file/data?
When not to use? • Small amount of data • Overhead not worth it • Only a few operations needed • Custom solution can yield better performance • Need to change data in unsupported way • e.g. modify pictures, or large amounts of text
Advantages of DBMS • Data Independence / Abstraction • Efficient Data Access • Data Integrity • Security • Data Administration • Concurrent Access
The Relational Model • Relation – a set of records. • Schema – description of data. • Schema specifies the field names (or attributes) • Students(sid: string, name: string, login: string, age: int, gpa: real)
Levels of Abstractions (Schemas) • External • User-level interactions “DDL” • Conceptual • Logical • Stored data in terms of DBMS • Physical • How Data is stored • Indexing
Data Independence • Logical • Changes in relations • Physical • Changes in file structure, indices, etc.
DBMS Components • ACID Properties • Atomicity – all or none • Consistency – data cannot be inconsistent • Isolation – concurrent transactions • Durability – changes will not be lost • Together these form the backbone of what makes a DBMS a DBMS
Integrity constraints • Ensure the data is good • It’s the C of the ACID standard • Make sure numbers are in range • Make sure strings are well formatted • Make sure dates are in proper order • GPA = 42.8? Or -3.1? • E-mail = “ smith@cs” – wasted space and could cause issues with some mail programs
Queries • DBMS Specific FRIENDLY vs. • Relational calculus PROOFY vs. • Relational algebra MIX
SQL • Structured Query Language • Developed by IBM in the 70s • Standardized by ANSI in 1986
Queries • Selection • SQL • SELECT Attribute • FROM Table • RA: • Simple! Let’s get a little more complex
Queries (continued) • SQL • SELECT Attribute • FROM Table • WHERE boolean expression • RA • What about multiple tables?
Queries (continued) • SQL • SELECT Attribute • FROM Table1, Table2 • WHERE boolean expression relating attributes from two tables • RA
Example • Find all student names who have GPA lower than 2.5 • List all (name,age) tuples of students who are 18 or older • Give login of everyone whose birthday is in the next 2 weeks
Homework Questions • Given the following Schema: Students(sid: string, name: string, login: string, age: int, gpa: real) • Write a SQL Statement to list all (name,age,gpa) tuples of students who are younger than their GPA*10. • Write the equivalent relational algebra expression.
References • Dewdney, A.K. The (New) Turing Omnibus. New York: Henry Holt and Company, 1993. • Ramakrishnan, Gehrke. Database Management Systems. Third Edition. McGraw Hill. Ithaca, New York. 2003.