Código SQL:
Ver originalCREATE TABLE Departamentos
(
CodDep INT PRIMARY KEY,
NomDep VARCHAR (20)
);
INSERT INTO Departamentos VALUES(10, 'Ventas');
INSERT INTO Departamentos VALUES(20, 'Informática');
INSERT INTO Departamentos VALUES(30, 'RRHH');
INSERT INTO Departamentos VALUES(40, 'Diseño');
INSERT INTO Departamentos VALUES(50, 'Dirección');
INSERT INTO Departamentos VALUES(60, 'Asesoria');
CREATE TABLE Empleados
(
CodEmp INT PRIMARY KEY,
NomEmp VARCHAR(20),
ApeEmp VARCHAR(20),
DirEmp VARCHAR(50),
PobEmp VARCHAR(30),
TelEmp VARCHAR(9),
DNIEmp VARCHAR(9),
EmailEmp VARCHAR(50),
SalEmp INT,
FnacEmp DATE,
CodDepEmp INT,
CONSTRAINT Emp_Dep_fk FOREIGN KEY (CodDepEmp) REFERENCES Departamentos (CodDep)
);
INSERT INTO Empleados
VALUES(1, 'Markel','Gonzalez','Altamira 32','Arrasate','654354345','72839402A','[email protected]',1250,'1992/10/30',10);
INSERT INTO Empleados
VALUES(2, 'Irene','Inda','San Pedro 12','Arrasate','943797989','76543214S','[email protected]',3456,'1995/12/03',20);
INSERT INTO Empleados
VALUES(3, 'Julen','Aja','Supereibar 20','Eibar','694356394','32454345E','[email protected]',1865,'1992/08/30',30);
INSERT INTO Empleados
VALUES(4, 'Iñaki','Garcia','Gipuzkoa kalea 20','Arrasate','943485769','72638597n','[email protected]',1145,'1994/07/18',10);
INSERT INTO Empleados
VALUES(5, 'Oihane','Lameirinhas','Braulio Iriarte kalea 7','Elizondo','948576809','67484957k','[email protected]',1250,'1990/02/28',30);
INSERT INTO Empleados
VALUES(6, 'Ane','Sanchez','Saskaitz Plaza 3','Iruña','948364758','72638385n','[email protected]',1250,'1986/03/10',30);
INSERT INTO Empleados
VALUES(7, 'Hamilton','Barandiaran','Paularena kalea 23','Doneztebe','943567890','38438597n','[email protected]',1675,'1988/07/22',20);
INSERT INTO Empleados
VALUES(8, 'Juan', 'Lopez', 'Portu kalea , 3-2º', 'Arrasate','612345678','12345678A','[email protected]',NULL,'1994/11/30',30);
INSERT INTO Empleados
VALUES(9, 'Andoni', 'Martinez', 'Madina , 45', 'Aretxabaleta','615436738','22345678B','[email protected]',NULL,'1992/06/30',50);
INSERT INTO Empleados
VALUES(10, 'Pepe', 'Iriarte', 'Antton kalea, 34', 'Aretxabaleta','645574738','32345478C','[email protected]',2125,'1988/08/30',20);
INSERT INTO Empleados
VALUES(11, 'Asier', 'Sanz', 'Gipuzkoa bidea, 23', 'Bergara','676523448','42345478D','[email protected]',1450,'1989/09/15',40);
INSERT INTO Empleados
VALUES(12, 'Benito', 'Lertxundi', 'San Andres , 10 - 5', 'Arrasate','692374738','52345478E','[email protected]',1855,'1990/10/12',10);
INSERT INTO Empleados
VALUES(13, 'Jon', 'Lasa', 'Olakua 10-D 5', 'Oñati','673234765','62345478F','[email protected]',1250,'1992/02/23',40);
INSERT INTO Empleados
VALUES(14, 'Mikel', 'Arregi', 'San Pedro , 10', 'Antzuola','943234765','72745477G','[email protected]',850,'1996/10/23',50);
INSERT INTO Empleados
VALUES(15, 'Miren','Txintxurreta','Kale Barria 13 3A','Oñati','943784567','79601245A','[email protected]',880,'1993/12/12',10);
INSERT INTO Empleados
VALUES(16, 'Aitor','Biain','San Juan kale 26 2C','Oñati','943781234','72840545Q','[email protected]',750,'1993/09/17',10);
INSERT INTO Empleados
VALUES(17, 'Juanjo','Zumalde','San Andres kalea 2 1ezk','Arrasate','943788910','76125001E','[email protected]',1350,'1992/10/12',20);
INSERT INTO Empleados
VALUES(18, 'Ainhoa','Agirre','Atzeko Kale 17 2B','Oñati','943710129','43857116L','[email protected]',1900,'1993/12/31',20);
INSERT INTO Empleados
VALUES(19, 'Oihane','Olalde','San Lorentzo 65 3esk','Oñati','943718008','72123456I','[email protected]',1475,'1994/12/01',30);
INSERT INTO Empleados
VALUES(20, 'Iñigo','Ugarte','Olakua 9 7D','Oñati','943782468','79876543E','[email protected]',2050,'1990/11/10',30);
INSERT INTO Empleados
VALUES(21, 'Mikel','Irizar','Kale Zaharra 32 2esk','Oñati','943781357','44017449P','[email protected]',780,'1992/12/31',40);
INSERT INTO Empleados
VALUES(22, 'Izaskun','Ibabe','Kale Barria 49 3ezk','Oñati','943717557','76290183A','[email protected]',1450,'1990/07/09',40);
INSERT INTO Empleados
VALUES(200, 'Izaskun','Ibabe','Kale Barria 49 3ezk','Oñati','943717557','76290183A','[email protected]',122450,'1990/07/09',40);
CREATE TABLE Proveedores
(
CodPro INT PRIMARY KEY,
NomPro VARCHAR(20),
DirPro VARCHAR(50),
PobPro VARCHAR(30),
TelPro VARCHAR(9)
);
INSERT INTO Proveedores VALUES(1, 'Acer','Avda. Euskadi , 12','San Sebastian','943667789');
INSERT INTO Proveedores VALUES(2, 'Media Mark','San Lorenzo, 27','Bilbao','943783376');
INSERT INTO Proveedores VALUES(3, 'Bikode','Kale Zaharra, 12','San Sbastian','943782134');
INSERT INTO Proveedores VALUES(4, 'Lizker','Ibarra, 22','Bilbao','943783374');
INSERT INTO Proveedores VALUES(5, 'HP','Olakua, 23','San Sebastian','943783165');
INSERT INTO Proveedores VALUES(6, 'Bull','Gros , 45','San Sebastian','943883134');
CREATE TABLE Recursos
(
CodRec INT PRIMARY KEY,
DesRec VARCHAR(50),
TipRec CHAR,
PreRec FLOAT,
FecRec DATE,
CodProRec INT,
CONSTRAINT Rec_Pro_fk FOREIGN KEY (CodProRec) REFERENCES Proveedores (CodPro)
);
INSERT INTO Recursos VALUES(1000, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(1001, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(1002, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(1003, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(1004, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(1005, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(1006, 'Portatil HP 6550b', 'H' , 656 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(2000, 'PC sobremesa HP 4210' , 'H' , 458 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(2001, 'PC sobremesa HP 4210' , 'H' , 458 , '2011-10-01' , 5);
INSERT INTO Recursos VALUES(3000, 'Impresora Fujitsu 2100', 'H' , 88 , '2009-05-01' , 4);
INSERT INTO Recursos VALUES(3001, 'Plotter Acer H56', 'H' , 2359 , '2011-11-01' , 6);
CREATE TABLE Usan
(
CodEmpUsa INT,
CodRecUsa INT,
FEntUsa DATE,
FDevUsa DATE,
CONSTRAINT Usa_pk PRIMARY KEY (CodEmpUsa, CodRecUsa, FEntUsa),
CONSTRAINT Usa_Emp_fk FOREIGN KEY (CodEmpUsa) REFERENCES Empleados (CodEmp),
CONSTRAINT Usa_Rec_fk FOREIGN KEY (CodRecUsa) REFERENCES Recursos (CodRec)
);
INSERT INTO Usan VALUES(1, 1001, '2012-12-31', '2013-02-15');
INSERT INTO Usan VALUES(1, 1001, '2012-02-30', '2013-01-02');
INSERT INTO Usan VALUES(7, 1001, '2014-08-28', NULL);
INSERT INTO Usan VALUES(15, 1002, '2012-05-13', NULL);
INSERT INTO Usan VALUES(20, 1003, '2012-09-21', NULL);
INSERT INTO Usan VALUES(22, 1004, '2012-10-30', NULL);
CREATE TABLE Incidencias
(
NumInc INT PRIMARY KEY,
DesInc VARCHAR(50),
FIniInc DATE,
FFinInc DATE,
CodRecInc INT,
CodEmpInc INT,
EstInc VARCHAR (50),
CONSTRAINT Inc_Rec_fk FOREIGN KEY (CodRecInc) REFERENCES Recursos (CodRec),
CONSTRAINT Inc_Emp_fk FOREIGN KEY (CodEmpInc) REFERENCES Empleados (CodEmp)
);
INSERT INTO Incidencias VALUES(1, 'Fallo arranque', '2012-09-02', '2012-11-06', 1000, 2, 'Arreglado');
INSERT INTO Incidencias VALUES(2, 'Fallo gráfica', '2012-09-28', NULL , 1001, 20, 'Pendiente');
INSERT INTO Incidencias VALUES(3, 'Tinta gastada', '2012-10-20', '2012-10-21' , 3000, 15, 'Arreglado');
INSERT INTO Incidencias VALUES(4, 'Fallo de impresión', '2012-10-15', NULL, 1003, 2, 'Pendiente');
INSERT INTO Incidencias VALUES(5, 'Fallo lectura HD', '2012-11-04', NULL, 1004, 1, 'Pendiente');
INSERT INTO Incidencias VALUES(6, 'Fallo arranque', '2012-11-29', NULL, 1000, 2, 'Pendiente');
CREATE TABLE Tareas
(
NumTar INT PRIMARY KEY,
DesTar VARCHAR(50),
FecTar DATE,
TieTar INT,
MatTar FLOAT,
NumIncTar INT,
CodEmpTar INT,
CONSTRAINT Tar_Inc_fk FOREIGN KEY (NumIncTar) REFERENCES Incidencias (NumInc),
CONSTRAINT Tar_Emp_fk FOREIGN KEY (CodEmpTar) REFERENCES Empleados (CodEmp)
);
INSERT INTO Tareas VALUES(1, 'Cambiar alimentador', '2012-11-03', 1, 0, 1, 2);
INSERT INTO Tareas VALUES(2, 'Cambiar la memoria RAM', '2012-11-03', 2, 20, 1, 18);
INSERT INTO Tareas VALUES(3, 'Reintalar Sistema operativo', '2012-11-04', 2, 0, 1, 18);
INSERT INTO Tareas VALUES(4, 'Configurar el equipo', '2012-11-06', 2, 0, 1, 18);
INSERT INTO Tareas VALUES(5, 'Revisar tarjeta gráfica', '2012-09-30', 1 , 0 , 2, 2);
INSERT INTO Tareas VALUES(6, 'Cambiar la tarjeta', '2012-09-30', 1 , 125.45 , 2, 18);
INSERT INTO Tareas VALUES(7, 'Cambiar cartucho de tinta', '2012-10-21', 1, 176, 3, 18);