Database L. Grewe.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizards Guide to PHP by David Lash.
Advertisements

Data Definition Language (DDL)
Introduction To SQL Lynnwood Brown President System Managers LLC Copyright System Managers LLC 2003 all rights reserved.
Concepts of Database Management Sixth Edition
Introduction to PL/SQL Lecture 0 – Self Study Akhtar Ali.
Structured Query Language SQL: An Introduction. SQL (Pronounced S.Q.L) The standard user and application program interface to a relational database is.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Oracle for Software Developers. What is a relational database? Data is represented as a set of two- dimensional tables. (rows and columns) One or more.
INTERNET APPLICATION DEVELOPMENT For More visit:
Copyright © 2003 by Prentice Hall Module 4 Database Management Systems 1.What is a database? Data hierarchy and data organization Field, record, file,
Copyright © 2003 Pearson Education, Inc. Slide 8-1 The Web Wizard’s Guide to PHP by David Lash.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
CS 3630 Database Design and Implementation. Your Oracle Account UserName is the same as your UWP username Followed Not case sensitive Initial.
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
SYST Web Technologies SYST Web Technologies Databases & MySQL.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Chapter 5: Part 1: DDL STRUCTURED QUERY LANGUAGE (SQL)
Concepts of Database Management Seventh Edition
1 Structured Query Language (SQL). 2 Contents SQL – I SQL – II SQL – III SQL – IV.
11 3 / 12 CHAPTER Databases MIS105 Lec15 Irfan Ahmed Ilyas.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
CS146 References: ORACLE 9i PROGRAMMING A Primer Rajshekhar Sunderraman
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
SQL Fundamentals  SQL: Structured Query Language is a simple and powerful language used to create, access, and manipulate data and structure in the database.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
 CONACT UC:  Magnific training   
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Introduction to Oracle. Before Computerized Database Organization use a set of data files to store each individual data. – The file contains individual.
CS242 SQL. What is SQL? SQL:  stands for Structured Query Language  allows you to access a database  is an ANSI standard computer language  can execute.
SQL Tutorial CPSC 608 Database System. Connecting to Oracle Your username is identical to your UNIX account To access your Oracle account, you need to.
Web Database Programming Using PHP
CIT 214 Introduction to Database Management
Aga Private computer Institute Prepared by: Srwa Mohammad
Fundamentals of DBMS Notes-1.
Introduction To Oracle
Web Systems & Technologies
SQL Query Getting to the data ……..
CS SQL.
CS 3630 Database Design and Implementation
Table spaces.
Module 11: File Structure
CS320 Web and Internet Programming SQL and MySQL
Database structure and space Management
SQL and SQL*Plus Interaction
Web Database Programming Using PHP
Introduction To Database Systems
Current outstanding balance
ORACLE SQL Developer & SQLPLUS Statements
ISC440: Web Programming 2 Server-side Scripting PHP 3
DATABASE MANAGEMENT SYSTEM
STRUCTURED QUERY LANGUAGE
Introduction To Structured Query Language (SQL)
Intro to Relational Databases
Creating Noninput Items
Introduction To Structured Query Language (SQL)
Contents Preface I Introduction Lesson Objectives I-2
Chapter 2: Creating And Modifying Database Tables
Spreadsheets, Modelling & Databases
Database Management Systems
MySQL Database System Installation Overview SQL summary
CS3220 Web and Internet Programming SQL and MySQL
Database administration
Introduction to Database systems
Introduction to Oracle
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

Database L. Grewe

Database Desired Features of a Database Management System (DBMS) Easy to store, retrieve, modify data Security Handle Concurrent Access Data Recovery Consistent Data Metadata should be available.

History Flat-FileNot really a database, simply store data in files. NetworkStores data in a network structure. HierarchicalStores in a hierarchical structure.  Old, not used anymore RelationalStores data in tables.  Makes use of the Math concepts of relations.  Since 1970s.  Example Oracle.    Object-orientedExpands upon Relational model to handle more complicated kinds of data in non-transactional manners.

Accessing Database Administration Many tools Some computer applications, some web interfaces Example of desktop application TOAD by Dell allows access to multiple databases Example of web interface --

Many databases

SQL or NoSQL SQL – structured query language -- used to access Relational databases

CAP theory Consistency Availability Partition tolerance Says it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees:[1][2][3] In other words, the CAP theorem states that in the presence of a network partition, one has to choose between consistency and availability. Consistency Availability Partition tolerance Every read receives the most recent write or an error Every request receives a (non-error) response – without guarantee that it contains the most recent write The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes

Which database SQL or NoSQL? Cost? Knowledge? Scaling? Features? Availability?

Following trends Search, read, meetups

We are not talking about data in cloud or distributed data Take CS 6320 to learn about these kinds of topics Your text here

Accessing Databases for Admin Use DBA tool –desktop apps and web interfaces

Relational Databases Data is organized in tables.  Each table consists of a set of columns, each column representing some item of information.   A relation represents an operation on a database described by Mathematical Set Operations such as unions and joins. A Union B  = all the elements of set A and B.  A Joint B = only the comment elements of set A and B.   For example, below is a table representing information about software distributors.    They keys here are "Name, Street Address, City, State, Distribute" Search a database by searching against certain key values which represent   For example, we may want to find all the entries in the Database that have the key State = CA.  To search a database you must use the language the Database understands.  Most relational databases understand a version of a scripting language called SQL. Name Street Address City State Distribute Butch Grewe 100 Campus Dr. Seaside CA Microsoft,  Adobe Doug MacIntire 100 6th Street. NY Enterprise Suite

Relational Database Relational Databases Tablespace Table Is a set of segments and consist of one or more data files.  May contain many kinds of multiple data objects such as tables, indexes, etc. EXAMPLES in Oracle System tablespace = Contains the data dictionary, stored procedures, triggers, and system rollback segment.  Used for system maintenance and operation. Data tablespace= Stores user data in tables and indexes.  User data tablespaces don't need to be online all of th time unlike system tablespace.  Need to be online in order to acces data in them. Note: There is often a defined default tablespace for each user. A user does not have to specify the tablespace when creating new objects, like tables, that they want to be in the default tablespace. The DBA sets up what the default tablespace is when creating a user. Temporary tablespace= Used by operations, such as sorting, unions, joins, that take up temporary space. Table Sits inside of a particular tablespace.  Contains data in a table (row, column) format. When creating a table you can specify the tablespace it is to be inside of. If not the default tablespace for the user is assumed.

How to think about databases TIP: Think of a database as a filing cabinent: the drawers withing the cabinet are tablespaces and the folders in those drawers are datafiles, and the pieces of paper in each folder are tables or other database objects, information written on a piece of paper is the data stored in the table.

Relational DB and SQL Structured Query Language = script language to manipulate a database

SQL: create table Using SQL*Plus to create a Table below are two examples of creating tables. The second specifies the tablespace the table should appear in, used if you have more than one tablespace. It also specifies the initial size, how it grows in size and minimum number of extents allocated for it.   SQL> create table customer( last_name       varchar2(30) not null, state_cd          varchar(2), sales                 number); SQL> create table products( name              varchar2(30) not null, description    varchar2(300), price             number(4,2) ) tablespace     productspace storage(initial 25k next 25k minextents 1); I prefer to use a GUI admin tool like TOAD or web interface to create table

SQL: Alter a table Using SQL*Plus to alter a Table Use the SQL alter command to add or drop columns in a table after it has been created. Suppose we have a table customer that has the following fields: last_name, state_CD, sales To add a column tax_exempt_id SQL>alter table customer add tax_exempt_id       varchar2(20); To drop the column sales SQL> alter table customer drop column sales;

CRUD – Create, Read, Update, Delete SELECT select * from table  select all the keys/fields from the table select Distribute from table select only the field Distribute from the table select * from table  where Name is 'Butch Grewe' Select all keys/fields from table where the key/field Name = Butch Grewe

CRUD – Create, Read, Update, Delete INSERT insert into table  values ('James Bond', '1 Eiffel Tower', 'Paris', 'France','Spy Software') Insert into the table, the data entry having the following key/field entries in order:  Name = James Bond  Street Address = 1 Eiffel Tower  City = Paris  State = France (huh???)  Distribute = Spy Software

CRUD – Create, Read, Update, Delete update table set age=6 where Name='Butch Grewe' updates any records with the name 'Butch Grewe' to have the value of 6 for the field age.

CRUD – Create, Read, Update, Delete delete from table where age=10 From table, deletes all records/rows that have the field of age with the value 10.

Conditional clauses The where clause where a1=x and a2=y ALL of the conditions must be true where a1=x or a1=y Only one of the conditions need to be true where a1=x or a2 >z where a1 between x and y Range of values where a1 not between x and y NOT in range of values where a1 in (x, y, z) Must be in the list of items where a1 not in (x,y,z) Must NOT be in the list of items. where a1 != x Must be NOT equal to value. where a1 like 'M%' Pattern Search....means a1 must start with a capital M. where a1 like '%son%' Pattern Search....means a1 must have somewhere in its value the string 'son'. Examples that would be good: Furgeson, Forsonning, etc. where a1 not like 'M%' Pattern Search....means a1 does NOT start with a capital M.

Order clause the order by clause select * from table order by name Order alphabetically in descending order the records in the table, by their value stored in the column name.

Oracle a relational database Identification You identify an Oracle Database by the following information: Host IP = IP address where Oracle Database under consideration is installed. Port = Port number of Oracle Database installation. SID = ID of the particular tablespace that describes the database you wish to access. The following shows an example of some items that could be listed in this file:    The first entry means the (134.154.11.126) server under port number 1521, Oracle was installed with an SID = labdb to identify the table space under question and that TCP communications protocol should be used in accessing it.  The second entry means that on the (207.62.129.150) server under port number 1521, Oracle was installed with an SID = intprog to identify the tablespace   labdb.world =      (DESCRIPTION =          (ADDRESS = (PROTOCOL = TCP) (HOST = 134.154.11.126) (PORT = 1521))          (CONNECT_DATA = (SID = labdb))        ) INTERNETPROG.WORLD =      (DESCRIPTION =          (ADDRESS = (PROTOCOL = TCP) (HOST = 207.62.129.150) (PORT = 1521))          (CONNECT_DATA = (SID = intprog))        )

Oracle data types Datatype Description Maximum Size CHAR fixed-length cahracter field, paded with trailing blanks char(size)                  char(30) //30 characters 2000 bytes VARCHAR Currently, same as CHAR varchar(size)           varchar(30)   VARCHAR2 Variable length character field varchar2(size) 4000 bytes LONG Variable length character data 2GB NUMBER Variable length numeric data number OR number(l,d)      where "l" stands for length and "d" for the number of decimal digits number(5,2)       can store numbers like 100.02 1x10^-130 to 9.99x10^125 BOOLEAN holds values of true or false only. This is actually a PL/SQL data type. DATE Data time values represents using format DD-MON-YY (e.g. 09-SEP-0 which means September 9, 2004). Dec 31, 9999 RAW Variable length raw binary data raw(size) 20000 bytes LONG RAW Variable-length raw binary data 2 GB

Datatype Description Maximum Size VARRAY New to Oracle 8i, an array that is an ordered list. varray(num_elements) of type e.g. varray(100) of number     // this is an array of                                                    maximum of  100                                                    numbers.   ROWID Row ID variable type 6 bytes User Defined Type User can define their own data type. You do so using the following SQL command. As a user, the DBA had to give you the privilege to be able to create user-defined data types. create type  your_data_type_name as XXXX where XXX specifies the kind of info you want represented as your_data_type. Here are two examples: create type price_list as varray(100) of number; create type room_type as object( capacity        number, podium         boolean, computers    number);

Oracle built in functions… go to oracle.com for more Meaning ABS absolute value CEIL ceiling FLOOR the floor MOD modular POWER x to power of y ROUND round off the number SIGN retrieve the sign SQRT square root TRUNC truncate AVG take the average MAX the maximum of set MIN the minimum of set STDDEV calculate standard deviation SUM take the sum SYSDATE get the current sytem date

PHP and connecting to Oracle (or any similar relational database) See http://us3.php.net/manual/en/intro.oci8.php AND http://us3.php.net/manual/en/ref.oci8.php for api and some additional examples <?php $user="login_CHANGE_THIS"; $password= "password_CHANGE THIS"; $host = "mcsdb2.sci.csueastbay.edu:1521/MCSDB2"; //CHANGE THIS //setup sql query $query = "SELECT * FROM DOGS WHERE AGE > " . @$_POST['age']; echo "Query is = " .$query; echo "<br>"; echo "Host is = " .$host; echo "<br>"; echo "<br>"; //connect to database, where tsnames.ora is setup $connect_obj = oci_connect($user, $password, $host); if($connect_obj) { echo "connected okay"; } else { $err = oci_error(); echo "Oracle connection error " . $err['message']; return; } Setting up host and account information To connect to an Oracle instance SQL query to table DOGS to retrieve all Connect to Oracle and if any problems report error

This is about executing the SQL statement and catching any exceptions Continued…… //create sql statement $sql_statement = oci_parse($connect_obj, $query) ; //execute statement try{ $r = oci_execute($sql_statement, OCI_COMMIT_ON_SUCCESS); if(!$r) { $p = oci_error($sql_statement); echo " <br> error in execution " . oci_error($p); } } catch(Exception $e) { echo "<br>Failed to get database info" . $e->getMessage(); } SQL statement object created using then oci php module Execute the SQL statement & results returned to $r If error report Catch any exceptions –like database not available, table doesn’t exist, etc

Free up the SQL statement and close connection – these are open resources and very important to free Continued…… //close the connection oci_free_statement($sql_statement); //need to free so close can work //without this it will not close //until this script ends if(!oci_close($connect_obj)) {echo " oci connection not closed!!!"; } ?>

What does this php code do? Very inefficiently (bad to do) makes a direct connection to data base, makes a single query and closes connection