Ayuda a hacer una relacion de tablas
Publicado por José Manuel (1 intervención) el 04/10/2015 22:43:23
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
create database ejercicio4_alter
use ejercicio4_alter
create table tipohabitacion(
codtipohabitacion varchar(2) not null,
precio int,
descripcion varchar(100),
constraint pk_tipohabitacion primary key(codtipohabitacion)
)
create table habitacion (
nrohabitacion varchar(4) not null,
descripcion varchar(100),
codtipohabitacion varchar(2),
ubicacion varchar(20),
tienebaño bit,
tienetv bit,
tieneaireacondicionado bit,
tienecalefaccion bit,
tienefriobar bit,
tieneyacusi bit,
estado tinyint,
constraint pk_habitacion primary key (nrohabitacion),
constraint fk_tipohabitacion_habitacion foreign key (codtipohabitacion) references tipohabitacion (codtipohabitacion),
)
create table turno (
codturno varchar(2) not null,
codempleado varchar(4),
descripcion varchar(20),
constraint pk_turno primary key (codturno),
)
create table cliente(
codcliente int not null,
nombreorazonsocial varchar(100),
direccionciudad varchar(100),
tipopersona tinyint,
dni varchar(8),
ruc varchar(11),
telefono varchar(30),
movil varchar(30),
constraint pk_cliente primary key (codcliente)
)
create table alquiler(
nroalquiler int not null,
codturno varchar(2),
codcliente int,
nrohabitacion varchar(4),
fechaalquiler datetime,
nrodias int,
monto numeric(18,2),
observaciones varchar(200),
estado tinyint,
constraint pk_alquiler primary key (nroalquiler),
constraint fk_habitacion_alquiler foreign key (nrohabitacion) references habitacion (nrohabitacion),
constraint fk_turno_alquiler foreign key (codturno) references turno (codturno),
constraint fk_cliente_alquiler foreign key (codcliente) references cliente (codcliente)
)
create table productos(
codproducto varchar(8) not null,
descripcion varchar(100),
umedida varchar(5),
stock numeric(18,2),
precioventa numeric(18,2),
ucosto numeric(18,4),
constraint pk_productos primary key (codproducto)
)
create table consumos (
nroalquiler int not null,
codproducto varchar(8) not null,
cantidad numeric(18,2),
precio numeric (18,2),
subtotal numeric(18,2),
constraint pk_consumos primary key (nroalquiler,codproducto),
constraint fk_alquiler_consumos foreign key (nroalquiler) references alquiler(nroalquiler),
constraint fk_productos_consumos foreign key (codproducto) references productos (codproducto)
)
-------------segunda etapa------------
create table empleados(
codempleado varchar(2) not null,
nombres varchar(100),
direccion varchar(100),
fechaingreso datetime,
constraint pk_empleados primary key (codempleado),
)
alter table consumos drop constraint fk_alquiler_consumos
alter table alquiler drop constraint fk_turno_alquiler
alter table alquiler drop constraint pk_alquiler
alter table alquiler drop column codturno
alter table alquiler add codempleado varchar(2) not null
alter table alquiler add constraint pk_alquiler primary key(nroalquiler,codempleado)
alter table alquiler add constraint fk_empleados_alquiler foreign key (codempleado) references empleados (codempleado)
alter table consumos add constraint fk_alquiler_consumos foreign key (nroalquiler) references alquiler (nroalquiler)-...............................AQUI EL PROBLEMA
A LA TABLA CONSUMOS LLEGAN DOS FORANEAS LA DE ALQUILER Y PRODUCTO
BORRE LA RELACION CON ALQUILER PARA CAMBIAR TIPO DE DATO
LUEGO INTENTE RELACIONARLOS NUEVAMENTE PERO NO ME DEJA
PERO LA RELACION PRODUCTOS_CONSUMOS ESA SI ESTA NORMAL
INTENTE BORRAR LA TABLA CONSUMO Y CREAR LA RELACION NUEVAMENTE Y NO ME DEJA
- sql.rar(24,7 KB)
Valora esta pregunta
0