Introducción a las bases de datos SQL Libro de referencia



Similar documents
Database: SQL, MySQL

Chapter 22 Database: SQL, MySQL,

Python Database Application Programming Interface (DB-API)

SQL. Short introduction

COMP 5138 Relational Database Management Systems. Week 5 : Basic SQL. Today s Agenda. Overview. Basic SQL Queries. Joins Queries

A basic create statement for a simple student table would look like the following.

SQL - QUICK GUIDE. Allows users to access data in relational database management systems.

Database Query 1: SQL Basics

Boats bid bname color 101 Interlake blue 102 Interlake red 103 Clipper green 104 Marine red. Figure 1: Instances of Sailors, Boats and Reserves

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

SQL: Queries, Programming, Triggers

SQL: Queries, Programming, Triggers

Using Multiple Operations. Implementing Table Operations Using Structured Query Language (SQL)

Information Systems SQL. Nikolaj Popov

Chapter 9 Joining Data from Multiple Tables. Oracle 10g: SQL

Introduction to Microsoft Jet SQL

Oracle 10g PL/SQL Training

Relational Databases. Christopher Simpkins

A Brief Introduction to MySQL

Learning MySQL! Angola Africa SELECT name, gdp/population FROM world WHERE area > !

Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification

CSI 2132 Lab 3. Outline 09/02/2012. More on SQL. Destroying and Altering Relations. Exercise: DROP TABLE ALTER TABLE SELECT

Lab # 5. Retreiving Data from Multiple Tables. Eng. Alaa O Shama

Chapter 5. SQL: Queries, Constraints, Triggers

Relational Algebra. Module 3, Lecture 1. Database Management Systems, R. Ramakrishnan 1

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

2874CD1EssentialSQL.qxd 6/25/01 3:06 PM Page 1 Essential SQL Copyright 2001 SYBEX, Inc., Alameda, CA

Introduction to Databases

History of SQL. Relational Database Languages. Tuple relational calculus ALPHA (Codd, 1970s) QUEL (based on ALPHA) Datalog (rule-based, like PROLOG)

Database Administration with MySQL

Chapter 9 Java and SQL. Wang Yang wyang@njnet.edu.cn

Oracle Database 10g: Introduction to SQL

David M. Kroenke and David J. Auer Database Processing: Fundamentals, Design and Implementation

SQL Programming. Student Workbook

CS 2316 Data Manipulation for Engineers

P_Id LastName FirstName Address City 1 Kumari Mounitha VPura Bangalore 2 Kumar Pranav Yelhanka Bangalore 3 Gubbi Sharan Hebbal Tumkur

DIPLOMA IN WEBDEVELOPMENT

BCA. Database Management System

Talking to Databases: SQL for Designers

Structured Query Language. Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics

Financial Data Access with SQL, Excel & VBA

A table is a collection of related data entries and it consists of columns and rows.

CSE 530A Database Management Systems. Introduction. Washington University Fall 2013

SQL Server. 1. What is RDBMS?

Curso SQL Server 2008 for Developers

Oracle Database 10g Express

Triggers & Packages. {INSERT [OR] UPDATE [OR] DELETE}: This specifies the DML operation.

Relational Algebra and SQL

Displaying Data from Multiple Tables

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Nebenfach)

RDBMS Using Oracle. Lecture Week 7 Introduction to Oracle 9i SQL Last Lecture. kamran.munir@gmail.com. Joining Tables

David M. Kroenke and David J. Auer Database Processing 11 th Edition Fundamentals, Design, and Implementation. Chapter Objectives

INFO/CS 330: Applied Database Systems


Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

Introduction to SQL and database objects

Profesor: M.T.I. Juvencio Mendoza Castelán

How To Create A Table In Sql (Ahem)

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

6 CHAPTER. Relational Database Management Systems and SQL Chapter Objectives In this chapter you will learn the following:

Using the SQL Procedure

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

3.GETTING STARTED WITH ORACLE8i

Performing Queries Using PROC SQL (1)

SQL Basics. Introduction to Standard Query Language

1.204 Lecture 3. SQL: Basics, Joins SQL

Oracle Database 12c: Introduction to SQL Ed 1.1

Deleting A Record Updating the Database Binding Data Tables to Controls Binding the Data Table to the Data Grid View...

Using AND in a Query: Step 1: Open Query Design

Darshan Institute of Engineering & Technology PL_SQL

Unit 10: Microsoft Access Queries

Chapter 1 Overview of the SQL Procedure

1. INTRODUCTION TO RDBMS

Curso SQL Server 2012 para Desarrolladores

SQL, PL/SQL FALL Semester 2013

Θεµελίωση Βάσεων εδοµένων

- Eliminating redundant data - Ensuring data dependencies makes sense. ie:- data is stored logically

Oracle Database: SQL and PL/SQL Fundamentals

Microsoft Access Lesson 5: Structured Query Language (SQL)

Demystified CONTENTS Acknowledgments xvii Introduction xix CHAPTER 1 Database Fundamentals CHAPTER 2 Exploring Relational Database Components

More on SQL. Juliana Freire. Some slides adapted from J. Ullman, L. Delcambre, R. Ramakrishnan, G. Lindstrom and Silberschatz, Korth and Sudarshan

Introduction to SQL ( )

IT2304: Database Systems 1 (DBS 1)

SQL SELECT Query: Intermediate

The process of database development. Logical model: relational DBMS. Relation

DATABASE DESIGN AND IMPLEMENTATION II SAULT COLLEGE OF APPLIED ARTS AND TECHNOLOGY SAULT STE. MARIE, ONTARIO. Sault College

Relational Database: Additional Operations on Relations; SQL

1. SELECT DISTINCT f.fname FROM Faculty f, Class c WHERE f.fid = c.fid AND c.room = LWSN1106

IT2305 Database Systems I (Compulsory)

Displaying Data from Multiple Tables. Copyright 2004, Oracle. All rights reserved.

Information Technology NVEQ Level 2 Class X IT207-NQ2012-Database Development (Basic) Student s Handbook

Databases. DSIC. Academic Year

GET DATA FROM MULTIPLE TABLES QUESTIONS

CHAPTER 12. SQL Joins. Exam Objectives

Displaying Data from Multiple Tables. Copyright 2006, Oracle. All rights reserved.

Ch.5 Database Security. Ch.5 Database Security Review

Transcription:

Introducción a las bases de datos SQL 1 Libro de referencia Java How To Program 3ed Edition Deitel&Deitel Prentice Hall, 1999 2

Introduction Relational-Database Model Relational Database Overview: The books Database SQL 3 Database Collection of data Introduction DBMS Database management system Stores and organizes data RDBMS Relational database management system Tables 4

Introduction (Cont.) SQL Relational database Structured Query Language 5 DB Major Tasks Defining Databases - involves specifying the data types, structures, and constraints for the data to be stored in the database. Constructing Databases - storing the data itself (populating) on some storage medium that is controlled by the DBMS. Manipulating Databases - querying the database to retrieve specific data, updating the databases, and generating reports from the data. 6

Database Languages DDL Data Definition Language Provides facilities for definining database objects. DML Data manipulation Language Provides features for specifying the processing to be performed on database objects. SQL provides both 7 Application Architectures 8

Relational database Table Rows, columns Relational Model Primary key Unique data SQL statement Query 9 Tables Authors Author ID FirstName LastName YearBorn 1 Harvey Deitel 1946 2 Paul Deitel 1968 3 Tem Nieto 1969 10

Redundant Table AuthorID FirstName LastName YearBorn ISBN 1 Harvey Deitel 1946 0-13-010671-2 2 Paul Deitel 1968 0-13-010671-2 1 Harvey Deitel 1946 0-13-020522-2 2 Paul Deitel 1968 0-13-020522-2 3 Tem Nieto 1969 0-13-020522-2 11 Related Tables Author ID FirstName LastName YearBorn Authors 1 Harvey Deitel 1946 2 Paul Deitel 1968 3 Tem Nieto 1969 AuthorISBN ISBN Author ID 0-13-010671-2 1 0-13-010671-2 2 0-13-020522-2 1 0-13-020522-2 2 0-13-020522-2 3 12

Relational Database A primary key is a column or set of columns that uniquely identifies the rest of the data in any given row. A foreign key is a column in a table where that column is a primary key of another table. 13 Relational Operations Projection sname rating yuppy 9 lubber 8 guppy 5 rusty 10 14

Projection 15 Relational Operations Selection sname rating yuppy 9 rusty 10 Rating > 8 16

Relational Operations Join sid sname rating age bid day 22 dustin 7 45.0 101 10/10/96 58 rusty 10 35.0 103 11/12/96 17 Join Types Inner Join Only the rows that match the search conditions are returned Left Outer Join Returns all matched rows, plus all unmatched rows from the table on the left of the join clause (use nulls in fields of non-matching tuples) Right Outer Join Returns all matched rows, plus all unmatched rows from the table on the right of the join clause Full Outer Join Returns all (matched or unmatched) rows from the tables on both sides of the join clause 18

Books Database Sample database Four tables,, and Relationships among the tables 19 Tabla Authors de la base de datos Books 20

Datos de la tabla Authors 21 Tabla Publishers 22

Datos de la tabla Publishers 23 Tabla AuthorISBN 24

Datos de la tabla AuthorISBN (parcial) 25 Tabla Titles 26

Datos de la tabla Titles (parcial) 27 Table Relationships authors authorid firstname lastname authorisbn 1 1 authorid isbn publishers publisherid publishername 1 titles isbn title editionnumber copyright publisherid imagefile price 28

Comandos SQL SQL keyword Description CREATE TABLE SELECT FROM WHERE GROUP BY ORDER BY INNER JOIN INSERT UPDATE DELETE Creates a table. Retrieves data from one or more tables. Tables involved in the query. Required in every SELECT. Criteria for selection that determine the rows to be retrieved, deleted or updated. Criteria for grouping rows Criteria for ordering rows. Merge rows from multiple tables. Insert rows into a specified table. Update rows in a specified table. Delete rows from a specified table. 29 Query SELECT Simplest form of a SELECT query SELECT * FROM tablename SELECT * FROM authors Select specific fields from a table (projection) SELECT authorid, lastname FROM authors 30

WHERE Clause specify the selection criteria SELECT columnname1, columnname2, FROM tablename WHERE criteria SELECT title, editionnumber, YearPublished FROM titles WHERE YearPublished > '1998' WHERE clause condition operators <, >, <=, >=, =, <> LIKE wildcard characters % and _ 31 AuthorID y apellido SELECT authorid, lastname FROM Authors 32

Autores nacidos despues de 1960 SELECT * FROM Authors WHERE YearBorn > '1960' 33 Autores cuyos apellidos empiezan con d SELECT * FROM Authors WHERE LastName LIKE 'd%' 34

Autores cuyo nombre tiene i como segunda letra SELECT * FROM Authors WHERE LastName LIKE '_i%' 35 Tabla Authors ordenada por apellido en orden ascendente SELECT * FROM Authors ORDER BY LastName ASC 36

Tabla Authors ordenada por apellido en orden descendente SELECT * FROM Authors ORDER BY LastName DESC 37 Tabla Authors ordenada por apellido y luego por nombre en orden ascendente SELECT * FROM Authors ORDER BY LastName, FirstName ASC 38

Libros de Titles cuyos títulos terminan en How to program ordenados en forma ascendente con respecto al título SELECT * FROM Titles WHERE Title LIKE '%How to Program' ORDER BY Title ASC 39 Combinar los datos de multiples tablas: JOIN Join the tables Merge data from multiple tables into a single view INNER JOIN SELECT columnname1, columnname2, FROM (table1 INNER JOIN table2) ON table1.columnname = table2.column2name 40

Author ID Combinar los datos de multiples tablas: JOIN Authors FirstName LastName YearBorn 1 Harvey Deitel 1946 2 Paul Deitel 1968 3 Tem Nieto 1969 AuthorISBN ISBN Author ID 0-13-010671-2 1 0-13-010671-2 2 0-13-020522-2 1 0-13-020522-2 2 0-13-020522-2 3 SELECT Authors.AuthorID, FirstName, LastName, YearBorn, ISBN FROM Authors INNER JOIN AuthorISBN ON Authors.AuthorID=AuthorISBN.AuthorID 41 Combinar los datos de multiples tablas: JOIN AuthorID FirstName LastName YearBorn ISBN 1 Harvey Deitel 1946 0-13-010671-2 1 Harvey Deitel 1946 0-13-010671-2 2 Paul Deitel 1968 0-13-020522-2 2 Paul Nieto 1968 0-13-020522-2 3 Tem Nieto 1969 0-13-020522-2 42

Autores y los ISBN de los libros que escribieron en orden ascendente por apellido y por nombre SELECT FirstName, LastName, ISBN FROM Authors INNER JOIN AuthorISBN ON Authors.AuthorID=AuthorISBN.AuthorID ORDER BY LastName, FirstName 43 Query TitleAuthor incluida en la base de datos SELECT Titles.Title, Titles.ISBN, Authors.FirstName, Authors.LastName, Titles.YearPublished, Publishers.PublisherName FROM (Publishers INNER JOIN Titles ON Publishers.PublisherID = Titles.PublisherID) INNER JOIN (Authors INNER JOIN AuthorISBN ON Authors.AuthorID = AuthorISBN.AuthorID) ON Titles.ISBN = AuthorISBN.ISBN ORDER BY Titles.Title 44

Ejecución del Query TitleAuthor 45 UPDATE UPDATE table_name SET column_name = new_value WHERE column_name = some_value Ejemplo UPDATE Authors SET FirstName = 'Juan' WHERE FirstName = 'Tem' 46

INSERT INTO INSERT INTO table_name VALUES (value1, value2, ) Ejemplo INSERT INTO Authors VALUES (4, 'bart', 'simpson', '1990') 47 DELETE DELETE FROM table_name WHERE column_name = some_value Ejemplo DELETE FROM Authors WHERE FirstName= 'bart' 48