Practica 7: Creación de la BDs - Departamento de Lenguajes y

Anuncio
escuela técnica superior
de ingeniería informática
Creación de la base de
datos
Departamento de
Lenguajes y Sistemas Informáticos
Ingeniería del Software de Gestión III
Índice
♦
♦
♦
♦
Introducción
Modelo de objetos
Modelo de datos
Script de creación de la BD
MySQL
♦ Características:
♦ DBMS relacional
♦ No integridad referencial (se podría)
♦ No permite selects anidados
♦ Herramientas:
♦ DBMS
♦ mysqld –console
♦ mysqladmin -shutdown
♦ MySQL Administrator
♦ Crear nuevas BDs
♦ Definir nuevos usuarios / definir los permisos
♦ MySQL Query Browser
♦ Lanzar consultas SQL al DBMS MySQL
MySQL Administrator
MySQL Administrator
MySQL Administrator/ Catálogo
MySQL Administrator/ Usuarios
MySQL Administrator/ Permisos
MySQL Query Browser
MySQL Query Browser
Consultas SQL
Vista de la BD
Ayuda
Scripts y Resultsets
Índice
♦
♦
♦
♦
Introducción
Modelo de objetos
Modelo de datos
Script de creación de la BD
Modelo de objetos del POS
Customer
<<Class Model>>
- customerID: String
...
1
placedbyCustomer
1
CreditCard
- holder: String
- number: String
- month: int
- year: int
1..*
1..*
payment
1..*
1
Order
- city: String
- email: String
- fax: String
- phone: String
- name: String
- state: String
- street: String
- zipcode: int
- orderID: String
- deliverto: Addres
- payment: CreditCard
- timeplaced: Date
- details:List
- placedbyCustomer: String
Detail
- note: String
- quantity: int
- product: Product
Address
deliverto
1..*
1
Product
- productID: String
- description: String
- price: int
Índice
♦
♦
♦
♦
Introducción
Modelo de objetos
Modelo de datos
Script de creación de la BD
Modelo de datos del POS
<<Physical Data Model>>
1
CreditCard
OID: varchar(50) = <<PK>>
holder: varchar(50)
number: varchar(50)
month: int
year: int
1..*
1..*
payment
1
deliverto
Order
OID: varchar(50) = <<PK>>
city: varchar(50)
email: varchar(50)
fax: varchar(50)
phone: varchar(50)
name: varchar(50)
street: varchar(50)
zipcode: int
OID: varchar(50) = <<PK>>
orderid: varchar(50)
addressOID: varchar(50) = <<FK >>
creditcardOID : varchar(50)=<<FK>>
timeplaced: bigint
placedbyCustomer: varchar(50)
Detail
OID: varchar(50) = <<PK>>
orderOID: varchar(50)=<<FK>>
productOID: varchar(50)=<<FK>>
note: varchar(250)
quantity: int
Address
1..*
1
Product
OID : varchar(50) = <<PK>>
productID: varchar(50)
description: varchar(250)
price: int
Índice
♦
♦
♦
♦
Introducción
Modelo de objetos
Modelo de datos
Script de creación de la BD
Script de creación de la BD
<<Physical Data Model>>
1
CreditCard
CREATE TABLE Address (
OID varchar(50) NOT NULL,
city varchar(50) NOT NULL,
email varchar(50),
fax varchar(50),
phone varchar(50),
name varchar(50) NOT NULL,
street varchar(50) NOT NULL,
zipcode int NOT NULL,
PRIMARY KEY(OID));
CREATE TABLE Orders (
OID varchar(50) NOT NULL,
orderID varchar(50) NOT NULL,
addressOID varchar(50) NOT NULL,
cerditCardOID varchar(50) NOT NULL,
timeplaced bigint NOT NULL,
placedbycustomer varchar(50) NOT NULL,
PRIMARY KEY(OID));
1..*
1..*
payment
OID : varchar(50) = << PK>>
holder: varchar(50)
number: varchar(50)
month: int
year: int
CREATE TABLE CreditCard (
OID varchar(50) NOT NULL,
holder varchar(50) NOT NULL,
number varchar(50) NOT NULL,
month int NOT NULL,
year int NOT NULL,
PRIMARY KEY(OID));
CREATE TABLE Detail (
OID varchar(50) NOT NULL,
orderOID varchar(50) NOT NULL,
productOID varchar(50) NOT NULL,
note varchar(250),
quantity int NOT NULL,
PRIMARY KEY(OID));
1
deliverto
Order
OID: varchar(50) = <<PK>>
city: varchar(50)
email: varchar(50)
fax: varchar(50)
phone: varchar(50)
name: varchar(50)
street: varchar(50)
zipcode: int
OID : varchar(50) = << PK>>
orderid: varchar(50)
addressOID: varchar(50) = <<FK >>
creditcardOID: varchar(50)=<<FK>>
timeplaced: bigint
placedbyCustomer: varchar(50)
Detail
OID : varchar(50) = << PK>>
orderOID: varchar(50)=<<FK>>
productOID: varchar(50)=<<FK>>
note: varchar(250)
quantity: int
1..*
Address
1
Product
OID: varchar(50) = <<PK>>
productID: varchar(50)
description: varchar(250)
price: int
CREATE TABLE Product (
OID varchar(50) NOT NULL,
productID varchar(50) NOT NULL,
description varchar(250),
price int NOT NULL,
PRIMARY KEY(OID));
Script de creación de la BD
DROP TABLE if exists Product;
CREATE TABLE Product (
oid varchar(50) NOT NULL,
productID varchar(50) NOT NULL,
description varchar(250),
price int NOT NULL,
PRIMARY KEY(OID));
INSERT INTO Product (OID, productID, description, price)
VALUES ('1', '1-161899M', 'Monitor', 150);
INSERT INTO Product (OID, productID, description, price)
VALUES ('2', '1-262399T', 'Teclado', 25);
INSERT INTO Product (OID, productID, description, price)
VALUES ('3', '1-663297R', 'Raton', 12);
INSERT INTO Product (OID, productID, description, price)
VALUES ('4', '1-164889C', 'CPU', 250);
Script de creación de la BD
DROP TABLE if exists Address;
CREATE TABLE Address (
OID varchar(50) NOT NULL,
city varchar(50) NOT NULL,
email varchar(50),
fax varchar(50),
phone varchar(50),
name varchar(50) NOT NULL,
street varchar(50) NOT NULL,
zipcode int NOT NULL,
PRIMARY KEY(OID));
DROP TABLE if exists CreditCard;
CREATE TABLE CreditCard (
OID varchar(50) NOT NULL,
holder varchar(50) NOT NULL,
number varchar(50) NOT NULL,
month int NOT NULL,
year int NOT NULL,
PRIMARY KEY(OID));
Script de creación de la BD
DROP TABLE if exists Detail;
CREATE TABLE Detail (
OID varchar(50) NOT NULL,
orderOID varchar(50) NOT NULL,
productOID varchar(50) NOT NULL,
note varchar(250),
quantity int NOT NULL,
PRIMARY KEY(OID));
DROP TABLE if exists Orders;
CREATE TABLE Orders (
OID varchar(50) NOT NULL,
orderID varchar(50) NOT NULL,
addressOID varchar(50) NOT NULL,
creditCardOID varchar(50) NOT NULL,
timeplaced bigint NOT NULL,
placedbycustomer varchar(50) NOT NULL,
PRIMARY KEY(OID));
!Gracias!
♦ ¿Podemos mejorar esta lección?
Mándanos un email a [email protected]
Descargar