© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University

Slides:



Advertisements
Similar presentations
Relational databases Week 8 Information Technologies 17:610:550:01 - Fall
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational Databases.
LBSC 690 Session #7 Structured Information: Databases Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under.
© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
Databases Week 7 LBSC 690 Information Technology.
Databases Week 6 LBSC 690 Information Technology.
Information Technologies Anselm Spoerri PhD (MIT)
LBSC 690: Session 7 Relational Databases
© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Introduction To Databases IDIA 618 Fall 2014 Bridget M. Blodgett.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
1 Relational Databases. 2 Find Databases here… 3 And here…
Copyright © 2010 Pearson Education, Inc. Publishing as Prentice Hall 1 1. Chapter 2: Relational Databases and Multi-Table Queries Exploring Microsoft Office.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Lecture 2 The Relational Model. Objectives Terminology of relational model. How tables are used to represent data. Connection between mathematical relations.
INTERNET APPLICATION DEVELOPMENT For More visit:
ASP.NET Programming with C# and SQL Server First Edition
Copyright © 2008 Pearson Prentice Hall. All rights reserved.1 1 Committed to Shaping the Next Generation of IT Experts. Chapter 2: Relational Databases.
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
The Relational Model. Review Why use a DBMS? OS provides RAM and disk.
Database Technical Session By: Prof. Adarsh Patel.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Wednesday, March 5, 2014 Session 6: Relational.
PHP meets MySQL.
MIS 301 Information Systems in Organizations Dave Salisbury ( )
Rensselaer Polytechnic Institute CSCI-4380 – Database Systems David Goldschmidt, Ph.D.
Relational Database Management Systems. A set of programs to manage one or more databases Provides means for: Accessing the data Inserting, updating and.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
Normalization (Codd, 1972) Practical Information For Real World Database Design.
PHP and MySQL CS How Web Site Architectures Work  User’s browser sends HTTP request.  The request may be a form where the action is to call PHP.
Databases Week 5 LBSC 690 Information Technology.
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2015, Fred McClurg, All Rights.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Relational Database. Database Management System (DBMS)
© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University
Zhangxi Lin Texas Tech University ISQS 6347, Data & Text Mining 1 ISQS 6339 Data Management and Business Intelligence Database Review.
Database Management Systems (DBMS)
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Introduction to MySQL Ullman Chapter 4. Introduction MySQL most popular open-source database application Is commonly used with PHP We will learn basics.
Data Modeling Session 12 INST 301 Introduction to Information Science.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Course Contents Overview: Database basics Lesson 1: Benefits of using a database Lesson 2: Table that data Lesson 3: Analyzing, viewing, and reporting.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
1 Finding Your Way Through a Database Exploring Microsoft Office Access.
N5 Databases Notes Information Systems Design & Development: Structures and links.
Getting started with Accurately Storing Data
CS320 Web and Internet Programming SQL and MySQL
Exploring Microsoft Office Access
Exploring Microsoft Office Access 2007
Chapter 8 Working with Databases and MySQL
CS1222 Using Relational Databases and SQL
Teaching slides Chapter 8.
Computer Science Projects Database Theory / Prototypes
Advanced Database Concepts: Reports & Views
CS3220 Web and Internet Programming SQL and MySQL
CS3220 Web and Internet Programming SQL and MySQL
Week 6 LBSC 690 Information Technology
Exploring Microsoft Office Access
Presentation transcript:

© Anselm SpoerriInfo + Web Tech Course Information Technologies Info + Web Tech Course Anselm Spoerri PhD (MIT) Rutgers University

© Anselm SpoerriInfo + Web Tech Course Lecture 9 - Overview Relational Databases SQL = Structured Query Language MySQL & MySQL Workbench –Create & Test “Connection” Setup –Create Table and Perform SQL Queries Lectures – Week 9 Content

© Anselm SpoerriInfo + Web Tech Course Websites that use Relational Databases

© Anselm SpoerriInfo + Web Tech Course Is the WWW a Relational Database? Fairly sophisticated search available –Crawler indexes pages on the Web –Keyword-based search for pages But, currently –Data is mostly unstructured and untyped –Can’t modify the data –Can’t get summaries, complex combinations of data –Few guarantees provided for freshness of data, consistency across data items, … The picture is changing –New standards, e.g., XML, Semantic Web, etc., can provide richer models of data

© Anselm SpoerriInfo + Web Tech Course How is Relational Database different from Spreadsheet? SpreadsheetRelational Database Your data is of a manageable data size There is no need for relationships between data You are primarily creating calculations and statistics You are working with large amounts of data You need to create relationships between your data You rely on external databases to analyze data

© Anselm SpoerriInfo + Web Tech Course Relational Database – Basic Concepts Relational Database –Collection of data, organized to support access –Models some aspects of reality Components of Relational Database Field = an “atomic” unit of data city Record = a collection of related fields address Table = a collection of related records addresses –Each record is one row in the table –Each field is one column in the table Database = a collection of tables student data Primary Key = field that uniquely identifies a record

© Anselm SpoerriInfo + Web Tech Course Simple Example NameDOBSSN John Doe04/15/ Jane Smith08/31/ Mary Adams11/05/ Field Field Name Record Primary Key Table

© Anselm SpoerriInfo + Web Tech Course Why “Relational”? Databases Model some Aspects of Reality Relational Database groups data using Common Attributes found in data set –The resulting "clumps" of organized data are much easier for people to understand –The grouping uses the relational model

© Anselm SpoerriInfo + Web Tech Course Relational Database – Terminology A relation is defined as a set of tuples that have the same attributes. A relation is usually described as a table, which is organized into rows and columns. All the data referenced by an attribute are in the same domain and conform to the same constraints.

© Anselm SpoerriInfo + Web Tech Course Registrar Example Want to create Database to Collect Enrolled Student Data What do we need to know (i.e., model)? –Something about students (e.g., first name, last name, , department) –Something about courses (e.g., course ID, description, enrolled students, grades) –Which students are in which courses

© Anselm SpoerriInfo + Web Tech Course First Try Put everything in a big table… Discussion: Why is this a bad idea? Need to Normalize the Data  Attribute can only have one value

© Anselm SpoerriInfo + Web Tech Course Goals of “Normalization” Remove Duplicates / Save Space –Save each fact only once More Rapid Updates –Every fact only needs to be updated once More Rapid Search –Finding it once is good enough Avoid Inconsistency –Changing data once changes it everywhere

© Anselm SpoerriInfo + Web Tech Course Second Try... With Normalization in Mind Student Table Department TableCourse Table Enrollment Table

© Anselm SpoerriInfo + Web Tech Course Approaches to Normalization and Keys Simple Data Domains –Start with “binary relationships” (pairs of related fields) –Group Attributes together wherever possible –Add keys where necessary Complicated Data Domain –Entity relationship modeling “Primary Key” uniquely identifies a record –Example: student ID in student table “Foreign Key” is primary key in other table –Does not have to be unique in the table where it is “foreign key”

© Anselm SpoerriInfo + Web Tech Course Second Try... With Normalization in Mind Student Table Department TableCourse Table Enrollment Table Primary Key Foreign key

© Anselm SpoerriInfo + Web Tech Course Relational Database Operations Joining Tables: JOIN Choosing Columns: SELECT –Based on their label Choosing Rows: WHERE –Based on their contents These can be specified together SELECT Student ID, Dept WHERE Dept = “History”

© Anselm SpoerriInfo + Web Tech Course Relational Database Operation – Join Tables “Joined” Table Student Table Department Table

© Anselm SpoerriInfo + Web Tech Course Relational Database Operation – SELECT SELECT Student ID, Department

© Anselm SpoerriInfo + Web Tech Course Relational Database Operation – WHERE WHERE Department ID = “HIST”

© Anselm SpoerriInfo + Web Tech Course Database Integrity and Integrity Constraints Example: Registrar Database Database must be Internally Consistent –All enrolled students must have entry in student table –All courses must have a name –…–… These Conditions must be true at any time –Specified when the database is designed –Checked when the database is modified Relational Database Management System –Ensures Integrity Constraints are always kept –Database contents need to reflect the real world –Helps avoid data entry errors

© Anselm SpoerriInfo + Web Tech Course Database Design Considerations Field Size Property –Set Field Size … –Always anticipate current field size may need to be larger Validation Rules –Used to avoid data entry errors by restricting what can be entered –Validation text needs to be used to provide explanation of the type of allowed data in a field Store Data in its Smallest Part for Greater Flexibility –Instead of one field for an address, use many –Instead of one field for a name, two or three Use Multiple Tables to Reduce Redundancy –The process is also referred to as normalization

© Anselm SpoerriInfo + Web Tech Course SQL – Querying Relational Database SQL = Structured Query Language Database computer language designed for Managing & Accessing Data in Relational Database Queries –Ask question about data –Receive answer back by returning subset of table data. –Use JOIN, SELECT, WHERE –Need semicolon ; at the end of query –SQL commands and keywords are case-insensitive

© Anselm SpoerriInfo + Web Tech Course Studentweb Account and Navigate to Course Folder For Exercise 5 and Project, use "studentweb.comminfo.rutgers.edu" server to store web pages since your MySQL databases there. Using your NetID (username and password), log into "account sync app“: This will provision all your studentweb resources for them (including settings permissions on your files or MySQL database). Once done, then you can log into studentweb server via SFTP using your NetID. Log into studentweb server  dropped into folder for your username. To access course folder for storing Ex5 and project so that you can communicate with your MySQL database, need to navigate to specific part of the studentweb server. The easiest way to do this is to paste "/www/studentweb.comminfo.rutgers.edu/htdocs/YourCourseFolder“ into the "Remote site" field in Filezilla.

© Anselm SpoerriInfo + Web Tech Course MySQL Username & Password MySQL user account password is NOT the same as for Your NetID (to avert potential security risk). Access Your MySQL password in your home directory, the same directory you are dropped into initially, in mysqlpassword.txt file (username/mysqlpassword.txt). Name of Your MySQL database = YourCourseFolder_NetIDusername Example: class _aspoerri Please contact if you have any technical problems accessing their account, folders, mysql account, or mysql database.

© Anselm SpoerriInfo + Web Tech Course MySQL Workbench – –Click Download –Windows Download: scroll down on the above page and Select Platform: "Microsoft Windows" and then Windows (x86, 32-bit), MSI Installer – (HTTP) – Complete Installation. –Mac Download: scroll down on the above page and Select Platform: "Mac OS X" and then Mac OS X 10.5 (x86, 32-bit), DMG Archive Download – (HTTP) – Complete Installation. New Connection Connection Method: Standard TCP / IP over SSH SSH Hostname: studentweb.comminfo.rutgers.edu SSH Username: yourNetIDusername (or yourSCILSNETusername) SSH Password: yourNetIDpassword (or yourSCILSNETpassword) MySQL Hostname: localhost MySQL Server Port: 3306 Username: yourMySQLusername Password: yourMySQLpassword

© Anselm SpoerriInfo + Web Tech Course Create New Connection

© Anselm SpoerriInfo + Web Tech Course SQL Demo – Create Table DatabaseToUse = YourCourseFolder_NetIDusername created for you USE DatabaseToUse; // tells SQL which database to use Note: if YourCourseFolder contains – hyphens then will trigger SQL error You can use the grave mark ` to escape names that contain reserved lexical symbols such as - Example: USE `class _studentUsername`; Workaround in MySQL Workbench: Double-click icon of database to use in left-hand panel below “Schemas” to tell SQL which database to use. CREATE TABLE classics ( author VARCHAR(128), title VARCHAR(128), type VARCHAR(16), year CHAR(4), id INT UNSIGNED NOT NULL AUTO_INCREMENT KEY) ENGINE MyISAM; DESCRIBE classics;

© Anselm SpoerriInfo + Web Tech Course SQL Demo – Add Data and Add Column INSERT INTO classics (author, title, type, year) VALUES('Mark Twain','The Adventures of Tom Sawyer','Fiction','1876');INSERT INTO classics(author, title, type, year) VALUES('Jane Austen','Pride and Prejudice','Fiction','1811');INSERT INTO classics(author, title, type, year) VALUES('Charles Darwin','The Origin of Species','Non- Fiction','1856');INSERT INTO classics(author, title, type, year) VALUES('Charles Dickens','The Old Curiosity Shop','Fiction','1841');INSERT INTO classics(author, title, type, year) VALUES('William Shakespeare','Romeo and Juliet','Play','1594'); DESCRIBE classics; ALTER TABLE classics ADD isbn CHAR(13); UPDATE classics SET isbn=' ' WHERE year='1876'; UPDATE classics SET isbn=' ' WHERE year='1811'; UPDATE classics SET isbn=' ' WHERE year='1856'; UPDATE classics SET isbn=' ' WHERE year='1841'; UPDATE classics SET isbn=' ' WHERE year='1594'; DESCRIBE classics;

© Anselm SpoerriInfo + Web Tech Course SQL Demo – Querying MySQL Database SELECT something FROM tablename; SELECT author FROM classics; SELECT DISTINCT author FROM classics; SELECT author, title FROM classics; SELECT author, title FROM classics WHERE author="Mark Twain"; SELECT author, title FROM classics WHERE isbn=" ";

© Anselm SpoerriInfo + Web Tech Course MySQL Workbench and SFTP MySQL Workbench – New Connection Connection Method: Standard TCP / IP over SSH SSH Hostname: studentweb.comminfo.rutgers.edu SSH Username: yourNetIDusername (or yourSCILSNETusername) SSH Password: yourNetIDpassword (or yourSCILSNETpassword) MySQL Hostname: localhost MySQL Server Port: 3306 Username: yourMySQLusername Password: yourMySQLpassword SFTP – Connect to Server with MySQL to Upload Pages Host Name: studentweb.comminfo.rutgers.edu User Name: yourNetIDusername (or yourSCILSNETusername) User Password: yourNetIDpassword (or yourSCILSNETpassword) Remember: Set Permissions = 755