0% found this document useful (0 votes)
78 views5 pages

DB - Id: IS NOT Null

The document details the creation of a database called bdDELIVPOST including tables for suppliers, motorcycles, repairs, maintenance, maintenance details, and repair parts. Relationships are defined between the tables and sample data is inserted. Tables are created with primary keys and foreign keys are added to define relationships between tables.

Uploaded by

Luis Cutipa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views5 pages

DB - Id: IS NOT Null

The document details the creation of a database called bdDELIVPOST including tables for suppliers, motorcycles, repairs, maintenance, maintenance details, and repair parts. Relationships are defined between the tables and sample data is inserted. Tables are created with primary keys and foreign keys are added to define relationships between tables.

Uploaded by

Luis Cutipa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

/* Crear la BD */

USE master
GO

SET DATEFORMAT YMD


GO

IF DB_ID('bdDELIVPOST') IS NOT NULL


DROP DATABASE bdDELIVPOST
GO

CREATE DATABASE bdDELIVPOST


ON PRIMARY
( NAME = bdDELIVPOST,
FILENAME = 'D:\ExFinal20182\BDatos\bdDELIVPOST.mdf',
SIZE = 3MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 20%
)
LOG ON
( NAME = bdDELIVPOST_log,
FILENAME = 'D:\ExFinal20182\BDatos\bdDELIVPOST_log.ldf',
SIZE = 1MB,
MAXSIZE = UNLIMITED,
FILEGROWTH = 2%
)
GO

/* MODULO: Mantenimiento
Crear Tablas
Crear Primary Key
Crear Foreign Kye
Crear Diagrama ER */

USE bdDELIVPOST
GO

Create table Proveedores (


IdProveedor int identity(1,1) Primary Key Not Null ,
RazonSocial nvarchar(50) Null ,
RUC nvarchar(15) Null ,
Direcccion nvarchar(50) Null ,
Vendedor nvarchar(50) Null ,
Telefono nvarchar(50) Null )
GO

Create table Motos (


IdMoto int identity(1,1) Primary Key Not Null ,
Placa nvarchar(50) Null ,
Modelo nvarchar(50) Null ,
Marca nvarchar(50) Null ,
AnoFab nvarchar(50) Null ,
SerieNum nvarchar(50) Null ,
FecAadq nvarchar(50) Null )
GO
Create table Repuestos (
IdRepuesto int identity(1,1) Primary Key Not Null ,
Repuestos nvarchar(50) Null ,
Stock int Not Null ,
PrecioUnit float Null )
GO

Create table Mantto (


IdMantto int identity(1,1) Primary Key Not Null ,
FecMantto nvarchar(50) Null ,
IdMoto int Not Null ,
IdSupervisor int Not Null ,
Estado nvarchar(50) Null ,
FecInternamiento nvarchar(50) Null ,
FecAlta nvarchar(50) Null ,
IdProveedor int Not Null )
GO

Create table ManttoDetalle (


IdMantto int Not Null ,
Num int Not Null Primary Key (IdMantto, Num) , --
Primary key dos columnas
ManttoFec nvarchar(50) Null ,
ManttoDescripcion nvarchar(50) Null ,
Criticidad nvarchar(50) Null ,
Estado nvarchar(50) Null ,
IdMecanico int Not Null)
GO

Create table ManttoRepuestos (


IdMantto int Not Null ,
Num int Not Null Primary Key (IdMantto, Num) , --
Primary key dos columnas
IdRepuesto int Not Null ,
FecSolicitud date Null ,
Repuesto nvarchar(50) Null ,
Cantidad int Null ,
PrUnit float Null ,
Total float Null )
GO
/* *************************************
Creación de Diagrama de Relaciones
************************************ */

USE bdDELIVPOST
GO

/* Relacion Mantto_Proveedores */
ALTER TABLE Mantto
WITH CHECK ADD CONSTRAINT FK_Mantto_Proveedores
FOREIGN KEY (IdProveedor)
REFERENCES Proveedores (IdProveedor)

ALTER TABLE Mantto


CHECK CONSTRAINT FK_Mantto_Proveedores
GO

/* Relacion Mantto_Motos */
ALTER TABLE Mantto
WITH CHECK ADD CONSTRAINT FK_Mantto_Motos
FOREIGN KEY (IdMoto)
REFERENCES Motos (IdMoto)

ALTER TABLE Mantto


CHECK CONSTRAINT FK_Mantto_Motos
GO

/* Relacion ManttoDetalle_Mantto */
ALTER TABLE ManttoDetalle
WITH CHECK ADD CONSTRAINT FK_ManttoDetalle_Mantto
FOREIGN KEY (IdMantto)
REFERENCES Mantto (IdMantto)

ALTER TABLE ManttoDetalle


CHECK CONSTRAINT FK_ManttoDetalle_Mantto

/* Relacion ManttoRepuestos_Mantto */
ALTER TABLE ManttoRepuestos
WITH CHECK ADD CONSTRAINT FK_ManttoRepuestos_Mantto
FOREIGN KEY (IdMantto)
REFERENCES Mantto (IdMantto)

ALTER TABLE ManttoDetalle


CHECK CONSTRAINT FK_ManttoDetalle_Mantto
GO

/* Relacion ManttoRepuestos_Repuestos */
ALTER TABLE ManttoRepuestos
WITH CHECK ADD CONSTRAINT FK_ManttoRepuestos_Repuestos
FOREIGN KEY (IdRepuesto)
REFERENCES Repuestos (IdRepuesto)

ALTER TABLE ManttoRepuestos


CHECK CONSTRAINT FK_ManttoRepuestos_Repuestos
GO
/* MODULO: Mantenimiento INSERT INTO
Ingreso de datos de prueba
*/

USE bdDELIVPOST
GO

INSERT INTO Motos VALUES


('AA-1478', 'FZS FI 2015','YAMAHA', '2015','87SWF98547','2015-05-26'), -- 1
('FQ-7589', 'YZF-R15' ,'HONDA' , '2010','98POLR1532','2010-11-18'), -- 2
('HH-6004', 'MT-03-2016' ,'YAMAHA', '2016','MT-03-PLH8','2016-09-21'), -- 3
('MT-9513', 'YZF-R1' ,'HONDA' , '2015','RF962400JH','2015-02-11') -- 4
GO

INSERT INTO Proveedores VALUES


('TODO MOTOS SAC','20141719548','AV. REPUBLICA DE PANAMÁ N° 854 -
MIRAFLORES','MONICA VASQUEZ','271-3400'),
('HONDA PERU' ,'20100113654','AV. AVIACION N° 3790- SURQUILLO'
,'RAUL FERNANDEZ','271-3434')
GO

INSERT INTO Mantto VALUES


('2015-01-10', 2, 1, 'REGULAR','2015-01-09','2015-01-12', 1), -- 1
('2016-03-25', 2, 1, 'REGULAR','2016-03-25','2016-03-29', 1), -- 2
('2016-05-26', 1, 1, 'BUENO' ,'2016-05-26','2016-06-26', 1), -- 3
('2017-01-13', 2, 1, 'REGULAR','2017-01-13','2017-01-20', 1 ), -- 4
('2017-05-21', 1, 1, 'BUENO' ,'2017-05-21','2017-05-26', 1 ), -- 5
('2018-05-15', 1, 1, 'BUENO' ,'2018-05-15','2018-05-25', 1 ), -- 6
('2018-09-21', 2, 1, 'REGULAR','2018-09-21','2018-10-31', 1), -- 7
('2018-11-04', 1, 1, 'BUENO' ,'2018-11-04','2018-11-11', 1 ) -- 8
GO

INSERT INTO ManttoDetalle VALUES


(1,1,'2015-01-10','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(1,2,'2015-01-11','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(2,1,'2016-03-25','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(2,2,'2016-03-27','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(3,1,'2016-05-28','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(3,2,'2016-05-28','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(4,1,'2017-01-15','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(4,2,'2017-01-15','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(5,1,'2017-05-22','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(5,2,'2017-05-22','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(6,1,'2018-05-25','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(6,2,'2018-05-25','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(7,1,'2018-09-23','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(7,2,'2018-09-24','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 ),
(8,1,'2018-11-04','CAMBIO PASTILLAS DE FRENO','ALTA','BUENO',10 ),
(8,2,'2018-11-10','CAMBIO DE BATERIA' ,'ALTA','MALO' ,10 )
GO
INSERT INTO Repuestos VALUES
('LLANTAS' ,50 , 15.25), -- 1
('BUJIAS' ,150, 1.25), -- 2
('FOCOS' ,500, 0.25), -- 3
('CLAXON' ,5 , 32.50), -- 4
('BATERIAS' ,10, 483.83), -- 5
('PASTILLAS PARA FRENOS' ,100, 297.37), -- 6
('FILTRO DE AIRE' ,11, 176.02), -- 7
('FILTRO DE ACEITE' ,20, 56.15), -- 8
('PEDAL CAMBIO' ,5, 102.11) -- 9
GO

INSERT INTO ManttoRepuestos VALUES


(1,1,6,'2015-01-10','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(1,2,5,'2015-01-11','BATERIA' , 1, 483.83, 483.83),
(2,1,6,'2016-03-25','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(2,2,5,'2016-03-27','BATERIA' , 1, 483.83, 483.83),
(3,1,6,'2016-05-28','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(3,2,5,'2016-05-28','BATERIA' , 1, 483.83, 483.83),
(4,1,6,'2017-01-15','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(4,2,5,'2017-01-15','BATERIA' , 1, 483.83, 483.83),
(5,1,6,'2017-05-22','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(5,2,5,'2017-05-22','BATERIA' , 1, 483.83, 483.83),
(6,1,6,'2018-05-25','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(6,2,5,'2018-05-25','BATERIA' , 1, 483.83, 483.83),
(7,1,6,'2018-09-23','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(7,2,5,'2018-09-24','BATERIA' , 1, 483.83, 483.83),
(8,1,6,'2018-11-04','PASTILLAS DE FRENO', 2, 297.37, 594.74),
(8,2,5,'2018-11-10','BATERIA' , 1, 483.83, 483.83)
GO

Diagrama Entidad - Relación

You might also like