Sunteți pe pagina 1din 5

Taller online Clase 11

Base de datos
Resultado de Aprendizaje: Construir objetos de base de datos utilizando SQL.

Asignatura Base de Datos


Taller online Taller Semana 11
Semana 11 – Lenguaje de Definición de Datos.
Tipo de Actividad Individual
Evaluación Formativa
Tiempo 80 minutos

ACTIVIDAD A DESARROLLAR:

Estimado estudiante
A continuación, se le presenta un diagrama físico de una situación que hemos venido haciendo en clases. Se le
pide a usted que:

• Utilizando SQL y lenguaje de definición de datos, construya las tablas con sus atributos y tipos de datos.

Adjuntamos, también, el modelo lógico que servirá de apoyo para la definición de los campos obligatorios.

Proveedor Sucursal
Compras
rut <pi> Integer <M> ID <pi> Integer <M>
dv Characters (1) <M> 1,n fecha Date & Time <M> nombre Variable characters (100) <M>
nombre Variable characters (100) <M> cantidad Integer <M> direccion Variable characters (100) <M>
1,n
direccion Variable characters (100) <M> precio Money <M> telefono Integer
telefono Integer pagado Boolean <M> email Variable characters (9)
email Variable characters (9) ID <pi>
rut <pi>

0,n 0,n

1,n

Vende
Producto
0,n precio Money <M>
codigo <pi> Integer <M> desde Date & Time <M>
nombre Variable characters (100) <M> hasta Date & Time <M>
codigo <pi> stock Integer

0,n

Ventas
fecha Date & Time <M>
precio Money <M>
cantidad Integer <M>

1
Taller online Clase 11
Proveedor
rut int <pk>
dv char(1)
nombre varchar(100) Sucursal
direccion varchar(100) ID int <pk>
telefono int nombre varchar(100) FK_SUCURSAL_VENTAS
email varchar(9) direccion varchar(100)
estado int telefono int
email varchar(9)
Compras
numeroCompra int <pk>
rut int <fk1>
FK_PROVEEDOR_COMPRAS ID int <fk2> FK_SUCURSAL_COMPRAS
fecha datetime
pagado bit

FK_SUCURSAL_VENDE
DetalleCompra
codigo int <pk,fk1>
numeroCompra int <pk,fk2> FK_COMPRA_DETALLE
cantidad int
precio money
Vende
ID int <pk,fk1>
Producto codigo int <pk,fk2>
FK_PRODUCTO_VENDE
codigo int <pk> precio money
FK_DETALLE_COMPRA_PRODUCTO nombre varchar(100) desde datetime
hasta datetime
stock int

FK_PRODUCTO_DETALLE_VENTA

DetalleVenta
Ventas
numeroVenta int <pk,fk1> FK_VENTA_DETALLE numeroVenta int <pk>
codigo int <pk,fk2>
ID int <fk>
precio money
fecha datetime
cantidad int

PAUTA DE EVALUACIÓN:

Criterios Puntos Obtenido


Aspectos Académicos del escrito.
Utiliza SQL para crear tablas 15
Crea con SQL, y según el modelo atributos, tipos de datos y
30
obligatoriedad
Crea con SQL, y según el modelo, las claves primarias 15
Crea con SQL, y según el modelo, las relaciones 20
Aspectos Formales del escrito.
Responde dentro del tiempo indicado 10
Entrega un trabajo presentable y ordenado. 10
TOTAL 100 puntos: = 7.0 (Exigencia al 60%)
Calificación final
Observaciones:

2
Taller online Clase 11

RESPUESTA:

create table COMPRAS (


NUMEROCOMPRA int not null,
RUT int not null,
ID int not null,
FECHA datetime not null,
PAGADO bit not null,
constraint PK_COMPRAS primary key (NUMEROCOMPRA)
)

create table DETALLECOMPRA (


CODIGO int not null,
NUMEROCOMPRA int not null,
CANTIDAD int null,
PRECIO money null,
constraint PK_DETALLECOMPRA primary key (CODIGO, NUMEROCOMPRA)
)

create table DETALLEVENTA (


NUMEROVENTA int not null,
CODIGO int not null,
PRECIO money null,
CANTIDAD int null,
constraint PK_DETALLEVENTA primary key (NUMEROVENTA, CODIGO)
)

create table PRODUCTO (


CODIGO int not null,
NOMBRE varchar(100) not null,
constraint PK_PRODUCTO primary key nonclustered (CODIGO)
)

create table PROVEEDOR (


RUT int not null,
DV char(1) not null,
NOMBRE varchar(100) not null,
DIRECCION varchar(100) not null,
TELEFONO int null,
EMAIL varchar(9) null,
ESTADO int null,
constraint PK_PROVEEDOR primary key nonclustered (RUT)
)

create table SUCURSAL (


ID int not null,
NOMBRE varchar(100) not null,
DIRECCION varchar(100) not null,
TELEFONO int null,
EMAIL varchar(9) null,
constraint PK_SUCURSAL primary key nonclustered (ID)
)

create table VENDE (

3
Taller online Clase 11
ID int not null,
CODIGO int not null,
PRECIO money not null,
DESDE datetime not null,
HASTA datetime not null,
STOCK int null,
constraint PK_VENDE primary key (ID, CODIGO)
)

create table VENTAS (


NUMEROVENTA int not null,
ID int not null,
FECHA datetime not null,
constraint PK_VENTAS primary key (NUMEROVENTA)
)

alter table COMPRAS


add constraint FK_PROVEEDOR_COMPRAS foreign key (RUT)
references PROVEEDOR (RUT)
go

alter table COMPRAS


add constraint FK_SUCURSAL_COMPRAS foreign key (ID)
references SUCURSAL (ID)
go

alter table DETALLECOMPRA


add constraint FK_COMPRA_DETALLE foreign key (NUMEROCOMPRA)
references COMPRAS (NUMEROCOMPRA)

alter table DETALLECOMPRA


add constraint FK_DETALLE_COMPRA_PRODUCTO foreign key (CODIGO)
references PRODUCTO (CODIGO)

alter table DETALLEVENTA


add constraint FK_VENTA_DETALLE foreign key (NUMEROVENTA)
references VENTAS (NUMEROVENTA)

alter table DETALLEVENTA


add constraint FK_PRODUCTO_DETALLE_VENTA foreign key (CODIGO)
references PRODUCTO (CODIGO)

alter table VENDE


add constraint FK_SUCURSAL_VENDE foreign key (ID)
references SUCURSAL (ID)

alter table VENDE


add constraint FK_PRODUCTO_VENDE foreign key (CODIGO)
references PRODUCTO (CODIGO)

4
Taller online Clase 11

alter table VENTAS


add constraint FK_SUCURSAL_VENTAS foreign key (ID)
references SUCURSAL (ID)

S-ar putea să vă placă și