Вы находитесь на странице: 1из 46

BASES DE DATOS

RELACIONAL OBJETO
(Universal Servers)

Prof. Mlaga

Caractersticas Principales

EXTENSIONES DE TIPOS DE DATOS


BSICOS
OBJETOS COMPLEJOS
HERENCIA
SISTEMA DE REGLAS

Prof. Mlaga

Extensiones de Tipos Bsicos


SQL-92

Integer
Floating-point number
Character string, fixed or variable
date, time, datetime, interval
Numeric and Decimal

Prof. Mlaga

Extensiones de Tipos Bsicos


Ejemplo 1: Calendario para el mercado de Bonos
create table Bond (
bond_id
coupon_rate
face_value
bought
matures
value

integer,
float,
decimal (10,2),
date,
date,
decimal (10,2)

update bond
set value = face_value + coupon_rate *(matures -bought)
Prof. Mlaga

Extensiones de Tipos Bsicos


Ejemplo 2: Alfabetizacin de caracteres que no son ASCII
(McTavish,MacTavish,MTavish)
create table Emp (
name
startdate
salary

varchar (30),
date,
int);

select name, salary


from emp
where name > McT and name < McU
order by acending name;
Prof. Mlaga

McTavish
MacTavish
MTavish

Extensiones de Tipos
Bsicos

Tipos definidos por el usuarios

Create type mytype_t (internallength=8);


Create table my_table (
name
varchar (30)
some_data mytype_t);
Create cast (varchar to mytype_t) as mytypeInput
Create cast (mytype_t to varchar) as mytypeoutput

Prof. Mlaga

Extensiones de Tipos de
datos Bsicos
Update emp
Set salary = 10000
Where name = Jane;
Cinco caracteres ASCII de 40 bits se convierten
(1,0,0,0,0) a 32 bit para almacenamiento interno.

Prof. Mlaga

Extensiones de Tipos de
datos Bsicos
Select salary
From emp
Where name=Jane
El salario esta almacenado en 32 bits
10011100010000 se convierte en valor
ASCII

Prof. Mlaga

Extensiones de Tipos de
datos Bsicos

Funciones definidas por el usuario

Create function hourly_pay (int Arg1)


Returning
Tamben podra implementarse
As
en un lenguaje soportado por
Select Arg1/2000
la BD
Select name
From emp
Where hourly_pay (salary) > 12.50;

Prof. Mlaga

Extensiones de Tipos de
datos Bsicos

Operadores definidas por el usuario

select name
from emp
where GreaterThan (salary, 1000);
create operator
binding oper-name
to function-name;

Prof. Mlaga

Extensiones de Tipos de
datos Bsicos

Agregaciones definidas por el


usuario

create aggregate median (integer) returns (integer) as


Initialize= my_func_1,
Iterate= my_func_2
Finalize=my_func_3;

Prof. Mlaga

Extensiones de Tipos de
datos Bsicos

UNIONES DINMICAS
ACTIVACION DESDE EL CLIENTE O
EL SERVIDOR
SEGURIDAD
CALLBACK
METODOS DE ACCESO
TAMAO ARBITRARIO DE LOS TIPOS
DE DATOS
Prof. Mlaga

Caractersticas Principales

EXTENSIONES DE TIPOS DE
DATOS BSICOS
OBJETOS COMPLEJOS
HERENCIA
SISTEMA DE REGLAS

Prof. Mlaga

Constructores de Tipos
Complejos
Objetos que estn compuestos de varios tipos
de datos definidos por el usuario.

Columas
Compuestos (Composites)
Conjuntos (Sets)
References

Prof. Mlaga

Tipos Columna
Son tipos que definen la organizacin de uno o ms
atributos miembros que colectivamente describirn
la estructura de uno ms objetos de columnas.
Create or Replace type Name_T as Object
(Col
Varchar2 (50) )
/
Describe la estructura de las columnas que almacenan
Informacin de tipo Nombre

Prof. Mlaga

Tipos Columna
No estn solo limitados a definiciones
de atributos nicos.
Create or Replace type Address_T as Object
(Addr1
Varchar2 (50),
Addr2
Varchar2 (50),
City_TX
Varchar2 (50),
St_CD
Varchar2 (2),
Ctry_CD
Varchar2 (3),
Zip_CD
Varchar2 (9)
/
Prof. Mlaga

Tipos Columna
Podramos definir un tipo de objeto basado en
tipo columna anterior.
Create or Replace type Contact_T as Object
(Person
Varchar2 (50),
Address
Address_T
/

Prof. Mlaga

Tipos Fila
Son tipos que definen la estructura completa
de un objeto tabla.
Create or Replace type Name_T as Object
(Col
Varchar2 (50) )
/

Create or Replace type Person_T as Object


(Persona_ID
number(10),
Lname_TX
Name_T,
Fname_TX
Name_T,
Bitrh_date
Date)
/

Si quisiramos el tipo de dato o la longitud de cada uno de los campos de


Nombre contenidos en el sistema, bastara con modificar solo Name_T

Prof. Mlaga

Tipos Fila
Create row type phone_t (
area
number
decription

varchar (3),
varchar(7),
varchar(20);

Create row type auto_t (


name
year
license

varchar(12),
int,
vachar(7);

Prof. Mlaga

Tablas Objeto
Son tablas que se estructuran sobre
los tipos de datos fila.
Create or Replace type Person_T as Object
(Persona_ID
number(10),
Lname_TX
Name_T,
Fname_TX
Name_T,
Bitrh_date
Date)
/

Create Table EMP of Person_T


(Persona_ID
not null,
Lname_TX
not null,
Fname_TX
not null,
Bitrh_date
not null,
Primary Key
(Person_ID)
/

Si quisiramos modificar el tipo de dato o la longitud de cada uno de los campos


de nombre, contenidos en el sistema bastara con modificar solo Name_T
Prof. Mlaga

Tablas Objeto
Create Table EMP of Person_T
(Person_ID
not null,
Lname_TX
not null,
Fname_TX
not null,
Bitrh_date
not null,
Primary Key
(Person_ID)
/
El nico incoveniente que tiene las tablas basadas en tipos filas
es que estas estn estrechamente vinculadas con la estructura de
su tipo fila asociado.

Prof. Mlaga

Tablas Objeto
Create row type employee_t (
name
stardate
salary
address
city
state
zipcode

varchar (30),
date,
int,
varchar(30)
varchar(30)
char(2),
int) ;

Create table emp of type employee_t;


Create table jobs (
job_desc
employee
Prof. Mlaga

varchar(30)
employee_t);

Tablas Objeto
Create row type dept_t (
dname
floor
manager
phone
autos
manager_ref
colors
workers

varchar(30)
int,
varchar (30)
phone_t,
set (auto_t),
ref(employee_t)
references (emp),
set(varchar(30)),
set (ref(employee_t)
references (emp)));

Create table dept of type dept_t;


Prof. Mlaga

Tipo Columna, Fila y Tabla


Objeto
CREATE OR REPLACE TYPE NAME_T AS OBJECT
(COL
VARCHAR2 (50) )
/
CREATE OR REPLACE TYPE PERSON_T
AS OBJECT(
PERSON_ID
NUMBER (10),
LNAME_TX
NAME_T,
FNAME_TX
NAME_T,
BIRTH_DATE
DATE)
/

Prof. Mlaga

CREATE TABLE EMP OF PERSON_T (


PERSON_ID
NOT NULL
LNAME_TX
NOT NULL
FNAME_TX
NOT NULL
BIRTH_DATE
NOT NULL
PRIMARY KEY (PERSON_ID)
/

Algunas consideraciones sobre


Estructuras de Datos O-R
Crear una tabla denominada PERSON para almacenar informacin relacionada
con gente. La tabla tendr un identificador nico y campos para el
nombre (first name), apellidos (last name) y fecha de nacimiento (birth date).
Create or Replace type Person_T as Object
(Person_ID
number,
Last_Name
Varchar2 (50),
First_Name
Varchar2 (50),
Bitrh_date
Date)
/

Create Table EMP of Person_T


(Person_ID not null Primary Key,
Last_Name not null,
First_Name not null,
Bitrh_date not null)
/

COMO AADIMOS UN INDICADOR


DE GENERO (GENDER_MF)?
Prof. Mlaga

Algunas consideraciones sobre


Estructuras de Datos O-R
Create or Replace Type
Person_T as Object
(Last_Name Varchar2 (50),
First_Name
Varchar2 (50),
Bitrh_date
Date,
Gender_MF
Char (1))

Create or Replace Type EMP_T as Object


(Emp_ID number (10) not null Primary Key,
EMP
Person_T)
/

Create Table Contact


(Contact_ID Number (10) not null Primary Key)
Contact
Person_T)
/

Las tablas relacionales pueden hacer referencia a


un tipo de dato columna, en lugar de ser un tipo
de objeto fila.
Prof. Mlaga

Caractersticas Principales

EXTENSIONES DE TIPOS DE
DATOS BSICOS
OBJETOS COMPLEJOS
HERENCIA
SISTEMA DE REGLAS

Prof. Mlaga

Herencia

La tercera caractersica de un OR es la capacidad de


soportar herencia de varias caractersticas de un
supertipo o de un subtipo.
Al igual que las extensiones de tipo bsicas y los
objetos complejos, esta tercera caracterstica nos
permite crear nuevos tipos de datos.
Existen herencia de datos y herencia de funciones

Prof. Mlaga

Herencia de Datos
LA HERENCIA DE DATOS DEBE PERMITIR AGRUPAR
LOS TIPOS DE DATOS COMPUESTOS JERRQUICAMENTE.
PERSON_T

STUDENT_T

EMPLOYEE_T

STUDENT_EMP_T

Prof. Mlaga

Herencia de Datos
Create row type person_t (
name

varchar(30));

Create row type employee_T (


salary int,
startdate date,
address varchar(30),
city
varchar(30),
state
varchar(30),
zipcode int)
under person_t;

Create row type studen_t (


gpa
under person_t
Prof. Mlaga

float)

Herencia de Datos Mltiple


Create row type student_emp_t (
percent

float)

under employee_t, student_t;

DEBIDO A QUE EL REGISTRO NAME APARECE


TANTO EN STUDENT_T COMO EN EMPLOYEE_T
EL TOTAL DE REGISTROS SERA NUEVE
-name heredado de person_t
-salary, startdate, address, city, state, zipcode heredado
de employee_t
-gpa heredado de student_t
-percent declarado en el tipo de dato
Prof. Mlaga

Herencia de Tablas
Select name
from only (emp)
Where salary = 10000;

Select name
from emp
Where salary = 10000;
PERSON

EMP

STUDENT

STUDENT_EMP

Prof. Mlaga

Herencia de Tablas
Create table person of type person_t;
Create table emp of type employee_t
under person;
Create table student of type student_t
under person;

Create table student_emp of type stuent_emp_t


under student, emp;

Prof. Mlaga

Herencia de Funciones
overpaid
Person_t

Employee_t

Student_t

Student_emp_t

overpaid

Prof. Mlaga

Herencia de Funciones
EL COMPORTAMIENTO DE LA HERENCIA EST
DETERMINADO POR SU ARGUMENTOS

Create function overpaid (student_emp_t, Arg1)


returns boolean
as select Arg1.salary>(select salary from emp
where name =Bill);

Select e. name
from only (emp) e
where overpaid (e);
Prof. Mlaga

Select s. name
from only (student_temp) s
where overpaid (s);

Caractersticas Principales

EXTENSIONES DE TIPOS DE
DATOS BSICOS
OBJETOS COMPLEJOS
HERENCIA
SISTEMA DE REGLAS

Prof. Mlaga

Reglas
PROTEGEN LA INTEGRIDAD DE LA DATA,
PERMITEN UNA LABOR DE MANTENIMIENTO
SENCILLA Y ES TIL PARA MODELAR LOS FLUJOS
DE TRABAJO DE APLICACIONES

PARADIGMA DE DE LAS REGLAS

.UPDATE-UPDATE
.QUERY-UPDATE
.UPDATE-QUERY
.QUERY-QUERY

ON <EVENT>

WHERE <CONDITION>
DO <ACTION>

Prof. Mlaga

Regla Update-Update
Create rule Mike_Jane-salary_synch
on update to emp.salary
where current.name = Mike
do update emp
set salary = new.salary
where name = Jane
COMO CONSECUENCIA DE LA ACTUALIZACIN EL
SUELDO DE JANE ES ACTUALIZADO A 52,500.

Update emp
set salary = 52500
where name = Mike
Prof. Mlaga

ESTA REGLA ESPERA POR UN


EVENTO DE
ACTUALIZACIN DEL SUELDO DE
MIKE, CUANDO
ESTO OCURRA AUTOMTICAMENTE
AJUSTUR EL DE
JANE.

Regla Query-Update
Create rule audit_salary_review
on select to emp.salary
where current.name = Mike
do insert into audit
values
(current.salary, user, current_datetime);
ESTA REGLA ESPERA UN EVENTO QUE ES LA OBTENCIN
DEL SALARIO DE MIKE. DE OCURRIR SE REGISTRA LA
OCURRENCIA EN UNA TABLA AUDIT CON LOS VALORES
RESPECTIVOS.

Prof. Mlaga

Regla Update-Query
Create alert alert_Mike_on_salary_review
(mechanism=callback)
Create rule alert_Mike_on_salary_change
on update to emp
where current.name=Mike
do raise alert alert_Mike_on_salary_review
AQU EL EVENTO ES UN UPDATE Y LA ACCIN ES GENERAR
UNA RESPUESTA AL USUARIO,. ESTAS REGLAS TAMBIN
SON CONOCIDAS COMO ALERTAS.

Listen (alert_Mike_on_salary_review)
Poll (alert_name)
Prof. Mlaga

Regla Query-Query
Create rule Jane_Mike_salary_synch
on select to emp.salary
where current.name=Jane
do instead
select salary
from emp
where name=Mike;
ESTA REGLA ESPERA POR UN EVENTO QUE EXTRAIGA
LA INFORMACIN DEL SALARIO DE JANE. UNAVEZ
DETECTADO EN VEZ DE EXTRAER EL DE JANE EXTRAE
EL SALARIO DE MIKE (INSTEAD)

Select salary
From emp
Where name=Jane

Prof. Mlaga

Reglas algunas
consideraciones

Mltiples reglas disparadas por el mismo evento


puede causar muchas veces resultados
impredecibles
Cadena de reglas pueden iniciar loops infinitos
Abortar parte de la accin de una regla tambin
aborta toda la transaccin
El tiempo de la activacin de una regla puede
hacer la diferencia en el estado ltimo de la bases
de de datos
Prof. Mlaga

Reglas algunas
consideraciones

Debe soportar eventos y acciones que sean ambas


extradas y actualizadas.
Debe tener la capacidad de estar integrado con
otras capacidades de la BD OR.
Debe soportar (inmediate, deferred) y (Same
Transaction, Different Transaction).
No debe permitir ciclos interminables.

Prof. Mlaga

PRINCIPALES BDRO

IBM
INFORMIX
ORACLE

Si bien es cierto todos estos productos se autodenominan


Bases de Datos Universales, existe diferencia entre ellos.
Principalmente esta diferencia radica en la capacidad de
aproximarse al concepto de BDRO, igual situacin ocurri
en los primeros aos de las BDR.

Prof. Mlaga

DB2 UNIVERSAL SERVER


RELATIONAL EXTENDERS

Text Extender
Image Extender
Video Extender
Audio Extender
FingerPrint Extender

Prof. Mlaga

INFORMIX UNIVERSAL SERVER


DATABLADES MODULES

Data Warehousing/Financial
Digital Media
Mapping and Spatial
Text/Document Management
Web/Electronic Commmerce

Prof. Mlaga

Вам также может понравиться