CIS 45, The Introduction. What is a database? What is data? What is information?

Similar documents
1.8 Database and data Data Definition Language (DDL) and Data Manipulation Language (DML)

Arbori Starter Manual Eugene Perkov

2SKILL. Variables Lesson 6. Remembering numbers (and other stuff)...

Intro. Scheme Basics. scm> 5 5. scm>

Basant Group of Institution

Mahathma Gandhi University

SQL Data Definition Language: Create and Change the Database Ray Lockwood

Relational Algebra. Study Chapter Comp 521 Files and Databases Fall

Unit 4 Relational Algebra (Using SQL DML Syntax): Data Manipulation Language For Relations Zvi M. Kedem 1

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

SQL OVERVIEW. CS121: Relational Databases Fall 2017 Lecture 4

How metadata can reduce query and report complexity As printed in the September 2009 edition of the IBM Systems Magazine

Unit 4 Relational Algebra (Using SQL DML Syntax): Data Manipulation Language For Relations Zvi M. Kedem 1

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

The name of our class will be Yo. Type that in where it says Class Name. Don t hit the OK button yet.

Rails + Legacy Databases Brian Hogan - RailsConf 2009 twitter: bphogan IRC: hoganbp

These are notes for the third lecture; if statements and loops.

Database Technology Introduction. Heiko Paulheim

Database Management Systems. Chapter 4. Relational Algebra. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

CGS 3066: Spring 2017 SQL Reference

Chapter01.fm Page 1 Monday, August 23, :52 PM. Part I of Change. The Mechanics. of Change

Introductory SQL SQL Joins: Viewing Relationships Pg 1

Text Input and Conditionals

COSC 2P91. Bringing it all together... Week 4b. Brock University. Brock University (Week 4b) Bringing it all together... 1 / 22

Oracle Database 10g: Introduction to SQL

Pointers in C/C++ 1 Memory Addresses 2

In This Lecture. SQL Data Definition SQL SQL. Non-Procedural Programming. Notes. Database Systems Lecture 5 Natasha Alechina

Week - 01 Lecture - 04 Downloading and installing Python

Chapter 1 SQL and Data

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

Grade 6 Math Circles November 6 & Relations, Functions, and Morphisms

Databases - 4. Other relational operations and DDL. How to write RA expressions for dummies

The Six Dirty Secrets of Tagging

G64DBS Database Systems. Lecture 7 SQL SELECT. The Data Dictionary. Data Dictionaries. Different Sections of SQL (DDL) Different Sections of SQL (DCL)

Relational Algebra. Chapter 4, Part A. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Some Extra Information on Graph Search

Boolean Expressions. Is Equal and Is Not Equal

SQL: Data Definition Language. csc343, Introduction to Databases Diane Horton Fall 2017

XNA Tutorials Utah State University Association for Computing Machinery XNA Special Interest Group RB Whitaker 21 December 2007

Boolean Expressions. Is Equal and Is Not Equal

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Relational Databases Fall 2017 Lecture 7

Custom Fields in QuickBooks

SQL Simple Queries. Chapter 3.1 V3.01. Napier University

Security. 1 Introduction. Alex S. 1.1 Authentication

C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

Data about data is database Select correct option: True False Partially True None of the Above

Relational Algebra. [R&G] Chapter 4, Part A CS4320 1

Certification Exam Preparation Seminar: Oracle Database SQL

Documenting APIs with Swagger. TC Camp. Peter Gruenbaum

Physical Design of Relational Databases

2.4 Choose method names carefully

Chamberlin and Boyce - SEQUEL: A Structured English Query Language

TECHNOLOGY: Ask Tom. As Published In. May/June 2011

PASSWORDS TREES AND HIERARCHIES. CS121: Relational Databases Fall 2017 Lecture 24

Learn Well Technocraft

Comments on drafts of final paper

How to Read AWStats. Why it s important to know your stats

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Excel Basics Rice Digital Media Commons Guide Written for Microsoft Excel 2010 Windows Edition by Eric Miller

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

Relational Algebra 1

1.2 Adding Integers. Contents: Numbers on the Number Lines Adding Signed Numbers on the Number Line

Introducing Databases

Quick Web Development using JDeveloper 10g

RELATIONAL QUERY LANGUAGES

Access Intermediate

12B. Laboratory. Databases. Objective. References. Write simple SQL queries using the Simple SQL applet.

LABORATORY. 16 Databases OBJECTIVE REFERENCES. Write simple SQL queries using the Simple SQL app.

Designing the staging area contents

This book is about using Visual Basic for Applications (VBA), which is a

Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi.

John W. Jacobs Technology Center 450 Exton Square Parkway Exton, PA Introduction to

B.H.GARDI COLLEGE OF MASTER OF COMPUTER APPLICATION. Ch. 1 :- Introduction Database Management System - 1

SQL: The Query Language Part 1. Relational Query Languages

IDP : conga/minisat(id)

Filter and PivotTables in Excel

Getting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

Sample Question Paper

Database Applications (15-415)

SQL: Concepts. Todd Bacastow IST 210: Organization of Data 2/17/ IST 210

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

MySQL Worst Practices. Introduction. by Jonathan Baldie

G64DBS Database Systems. Lecture 6 More SQL Data. Creating Relations. Column Constraints. Last Lecture s Question

CS121 MIDTERM REVIEW. CS121: Relational Databases Fall 2017 Lecture 13

PYTHON YEAR 10 RESOURCE. Practical 01: Printing to the Shell KS3. Integrated Development Environment

5 R1 The one green in the same place so either of these could be green.

Presto 2.0. Using Presto Rules

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

Relational Query Languages. Relational Algebra. Preliminaries. Formal Relational Query Languages. Relational Algebra: 5 Basic Operations

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

QUIZ. What is wrong with this code that uses default arguments?

This is a book about using Visual Basic for Applications (VBA), which is a

CSC 220: Computer Organization Unit 10 Arithmetic-logic units

Learn Relational Database from Scratch. Dan Li, Ph.D. Associate Professor Computer Science Eastern Washington University

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

UNIVERSITY OF CALIFORNIA, SANTA CRUZ BOARD OF STUDIES IN COMPUTER ENGINEERING

T H E I N T E R A C T I V E S H E L L

Database Foundations. 6-1 Introduction to Oracle Application Express. Copyright 2015, Oracle and/or its affiliates. All rights reserved.

Transcription:

CIS 45, The Introduction I have traveled the length and breadth of this country and talked with the best people, and I can assure you that data processing is a fad that won t last out the year. The editor in charge of business books for Prentice Hall, 1957 What is a database? Pretty much anything that stores/organizes data is a database in some sense. WordNet 1 defines a database as: an organized body of related information. Thus, the most important detail that we re concerned with is organized or more precisely, structured data. For example: a book stores data, a web-page stores data, etc., but they don t have well defined structure. Databases (as we use the term) store data according to the defined metadata which is the structure of the database. The difference is that databases are not defined by their data, but by the structure. For example, a book without text is pointless, but a database with no data is still a database; it has table structure defined, even though those tables may not contain any data. What is data? Well, we ve defined what is a database. But what exactly are we storing in this database? As the name implies, we are storing data. Data (by itself) is a set of entities. This is really a broad definition anything is an entity. Considering object oriented perspective, you can also think of entities as objects. Entities generally have various attributes (also commonly known as properties). These are what differentiages one entity from another. Attributes have values (a person may have an age attribute). Attributes may also reference other entities (a person may have a parent attribute that points to another person). What is information? Ignoring the dictionary definition, information is not a synonym of data. In fact, you can have gigabytes of data, yet have no information. Just consider a random sequence. The whole purpose of databases (and computers in general) is to work with information. Often times, computers are used to sift through lots of data to extract information. Generally, data has little or no value. Information on the other hand can be priceless. 1 WordNet is a machine-readable lexical database organized by meanings (i.e.: a dictionary); developed at Princeton University. 1

Broad Field While we will be mostly concerned with stand-alone databases, many programs have relatively sophisticated data storage and processing capabilities. Just consider how much data a typical computer game handles without some organization these things wouldn t be possible. So to paraphase a quote I ve seen once: computer games are just databases with pretty interfaces. Tuples A tuple is structured data a row in a table. It is something that we stored in a database as a single record. Considering the object oriented perspective, these are instances of entity objects. Tables Tables sometimes known as relations are basically just lists of tuples. To define a table, we need: table name, table fields, and a primary key. Name The name of the table is quite easy. It it usually a single word name of some entity. For example Person may be the name of table that has person records. There is a bit of a confusion as to whether table names should be singular or plural. ie: should you name a table User or Users. It is upto you to decide which way is best. Fields/Attributes Every table needs to have one or more fields (also known as attributes). A field needs to have a name, and more often than not, a type as well. The name should be picked with great care: it should be relatively descriptive, and appropriate to the type of information it represents. For example, using FIRSTNAME to represent first name. A field type is the data format that the field holds. For example, an INT field type would hold integer values, while a CHAR field type would host character data. Fields often have many other parameters, like comments, indicators if the field is a primary key, default values, valid/invalid values, etc. Primary Key A primary key is one or more fields that uniquely identify each individual row (record, tuple, etc.) in the database. 2

For example, a person s SS# (social security number) uniquely identifies each individual, etc. 2 Relational Databases The idea of relational databases isn t really anything special. It just means that our data is stored as several tables, which are somehow related to each other. For example, we can have a table with company information, and another table with employee information. Those two tables may be related to each other (details to be discussed later) to indicate which employee works for each company. Operations on Tables Once we have tables, what can we do with them? Well, there are five basic operations that can be performed: select, project, union, difference, and product. The following describes each one in some detail. Select The select operation retrieves data from a table on some condition. For example, we can imagine a statement that says: select all persons whose name is John Doe. Note that this example is a bit trivialized. We can use various operations in conditions, for example: select all persons whose first name is John and who are 21 or older. Project Projection operation extracts one or more columns from a table. For example, the Person table may have 20 various fields, but the project first name and last name from Person table only gets us first names and last names. The result has just as many records as went in; just with possibly fewer columns. One important concept is that we can combine operations, so for example, we can have project first name and last name from (select all persons whose first name is John and who are 21 or older). Union Union just combines all records of two tables. For this to work, the two tables must have the same number of columns (of matching data type). 2 As we ll discuss later, it is usually a very bad idea to use SS# as a primary key. 3

Difference The difference is similar to a Union, except it has the effect of removing records. For example: Table1 - Table2 would result in all records that are in Table1 but are not in Table2. Product The product operation (or ) is a Cartesian product of two tables. For example, if we have a table A = (a, b, c), and table B = (d, e, f), the product would be: A B = {(a, d), (a, e), (a, f), (b, d), (b, e), (b, f), (c, d), (c, e), (c, f)} Notice that A and B both have 3 elements, and that the product has 9. Join While join isn t exactly a basic table operation 3 it is useful enough to be considered on its own. Join (written ) is very much like the product operation, except often it doesn t produce all possible pairs. When the fields happen to have the same name, the join operation tries to match on those fields. When the join is only on the equality condition, then it is called a natural join. Note that we can also specify our own conditions for join. For example, using A and B as defined above, the: A B where both are vowels, will produce just {(a, e)}. Structured Query Language The table operations discussed so far are mostly for abstract thinking about databases. For every-day database manipulation, most databases have settled on a standard languaged called SQL, for Structured Query Language. There are two primary parts to SQL: The DDL and DML. DDL - Data Definition Language This is a standard subset of SQL that is used to define tables (database structure), and other metadata related things. The few basic commands include: CREATE DATABASE, CREATE TABLE, DROP TABLE, and ALTER TABLE. There are many other statements, but those are the ones most commonly used. DML - Data Manipulation Language This is a standard subset of SQL that is used for data manipulation. Intuitively, we need to first inset data into the database. Once it s there, we can retrieve it, modify it, and delete it. These directly correspond to: INSERT, SELECT, UPDATE, and DELETE statements. 3 Join can be defined using the five basic operations defined above. 4

Flavors of SQL Basically every database implements its own version of SQL. The basic statements (like the ones listed above) are almost always there and are almost always exactly the same on all databases. Extensions come in when you re trying to do something fancy, like create stored procedures, or work with a specific database environment. Microsoft SQL Server use a variant called T-SQL, for Transact-SQL. To contract, Oracle uses PL/SQL, for Procedural Language SQL. 5