0% found this document useful (0 votes)
19 views34 pages

Delivery 2 Database Fundamentals v2

The document outlines the design and implementation of a database for managing a mechanical workshop, detailing the creation of an Entity-Relationship diagram, relational model, and data dictionary. It specifies the requirements for managing customer, vehicle, employee, and spare part information, as well as the procedures for generating invoices and ensuring data integrity. The document also includes SQL scripts for the physical model of the database created in MySQL.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views34 pages

Delivery 2 Database Fundamentals v2

The document outlines the design and implementation of a database for managing a mechanical workshop, detailing the creation of an Entity-Relationship diagram, relational model, and data dictionary. It specifies the requirements for managing customer, vehicle, employee, and spare part information, as well as the procedures for generating invoices and ensuring data integrity. The document also includes SQL scripts for the physical model of the database created in MySQL.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Building a database for the management of a mechanical workshop

Activity in context – Second installment

Authors:

Maribel Cuellar Coy – code 1922010110

Myriam Andrea Moreno Cardona – 1922010141

Mario Leonardo De La Hortua Quiroga code 1411020729

Paula Hernandez Angulo - code 522040265

Rodrigo Alberto Ramirez Vargas – code 1922010203

Tutor:

Isabel Andrea Mahecha Nieto

Grancolombiano Polytechnic University Institution

Faculty of Administrative and Economic Sciences

Specialization in Business Intelligence Project Management

Bogota, December 2019


TABLE OF CONTENTS

Introduction......................................................................................................................................4

Activity approach.............................................................................................................................5

Problem............................................................................................................................................5

Entity-Relationship Diagram...........................................................................................................6

Relational model..............................................................................................................................7

Scheme.............................................................................................................................................8

Data dictionary...............................................................................................................................10

Restrictions....................................................................................................................................11

Physical Model..............................................................................................................................12

SQL scripts exported from My SQL:............................................................................................13

Activity 2 Approach.......................................................................................................................18

o Creating users and connection permissions..........................................................................18

o Creating tables and triggers for handling incremental sequences........................................18

o Invoice generation procedure...............................................................................................22

o Procedure for creating spare parts........................................................................................23

o Procedure for assigning spare parts to the service...............................................................24

o Procedure for assigning employees to the service................................................................24

o Service Creation Procedure..................................................................................................25

o Vehicle creation procedure...................................................................................................26

o Procedure for creating employees........................................................................................27


o Procedure for creating people...............................................................................................28

o Client creation procedure.....................................................................................................29

o Data display function............................................................................................................30

o Check functions....................................................................................................................30

How to ensure ACID properties....................................................................................................34

Literature........................................................................................................................................37

Data Dictionary Table1..................................................................................................................10

Table2 Restrictions........................................................................................................................11
Introduction

As part of the activities of the subject of database fundamentals, the activity is the design

of a database for the administration of a mechanical workshop applying the concepts of

diagramming entity-relationship models, schema and relational model as initial steps in the

construction of said database.

For the construction of this activity, the application developed in 1977 by Peter Chen is used as a

basis, (García-Molina)which has as essential modeling elements the entities, the relationships

and the attributes, which are the starting point for the development of this work and at the same

time to be able to carry out the relational model of the proposed exercise in order to apply the

theory of data sets, evidencing its differentiation with the ER model.


Activity approach

Design the Entity-Relationship diagram, relational schema and model, data dictionary,

and constraints.

Problem

You are hired to build a database for the management of a mechanical workshop. The

database will include information about customers, cars, employees working in the workshop

and the spare parts used for each service.

The database must:

 Register the client and car for each service.


 The client's ID, first and last names, telephone number and address are recorded.
 The license plate, model, color, date and time of entry are recorded for the car.
 An available employee is assigned to each service.
 The employee in charge of the service will register the spare parts with their reference,
description,
 brand and price as well as the hours spent on the service.
 Based on the price of spare parts, the number of hours used and the utility
 estimated, an invoice is created that also includes a 19% VAT.
Entity-Relationship Diagram.

ER Diagram Illustration1
Relational model

Illustration2 Relational Model


Scheme

PERSON(ID:string, names:string, surname_1:string, surname_2:string)

EMPLOYEE(employee_id:integer,ID:string,status_id:integer)
FOREIGN KEY: ID card REFERENCE ID card IN PERSON

STATUS(state_id:integer, state_description:string)

CUSTOMER(customer_id:integer,ID:string,address:string,landline:string,mobile_phone:string)
FOREIGN KEY: ID card REFERENCE ID card IN PERSON

VEHICLE(license plate:chain, customer_id:integer, model:integer, color:chain, brand:chain)


FOREIGN KEY: id_cliente REFERENCE id_cliente IN CLIENT

SPARE PART(spare_id:integer, reference:string, description:string, brand:string, price:integer)

SERVICE(service_id:integer, client_id:integer, license plate:string, employee_id:integer,


description:string, vehicle_entry_datetime:date, number_of_hours:integer)
FOREIGN KEY: id_cliente REFERENCE id_cliente IN CLIENT
FOREIGN KEY: plate REFERENCE plate IN VEHICLE
FOREIGN KEY: employee_id REFERENCE employee_id IN EMPLOYEE

SPARE_SERVICE(service_id:integer, spare_id:integer, quantity:integer, unit_price:integer,


registration_date:date)
FOREIGN KEY: id_repuesto REFERENCE id_repuesto IN SPARE

INVOICE(invoice_id:integer, service_id:integer, generation_date:date,


service_hour_value:integer, spare_parts_value:integer, VAT_percentage:integer)
FOREIGN KEY id_servicio REFERENCE id_servicio IN SERVICE
Data dictionary

Data Dictionary Table1

Entity Attribute Data Type Length PK/FK Description

PERSON ID card INT 6 PK Identity card that identifies the


person
names VARCHAR 45 Name of the person
surname_1 VARCHAR 45 First surname of the person
surname_2 VARCHAR 45 Second surname of the person
CUSTOMER client_id INT 6 PK Number that identifies the client
address VARCHAR 45 Customer address
landline VARCHAR 45 Customer's landline
mobile_phone VARCHAR 45 Customer's mobile phone
ID card INT 6 FK Identity card that identifies the
person
VEHICLE plate VARCHAR 6 PK Car plate
model VARCHAR 45 Car model
color VARCHAR 45 Color of the car
brand VARCHAR 45 Car brand
client_id INT 6 FK Number that identifies the client
EMPLOYEE_STATUS state_id INT 6 PK Number that identifies the
employee's status
status_description VARCHAR 45 FK Employee Status Description
EMPLOYEE employee_id INT 6 PK Number that identifies the
employee
state_id INT 6 FK Number that identifies the
employee's status
ID card INT 6 FK Identity card that identifies the
person
SPARE PARTS spare_id INT 6 PK Number that identifies the spare
part reference
reference VARCHAR 45 Spare part reference
spare_description VARCHAR 200 Spare part description
spare_brand VARCHAR 45 Spare part brand
price FLOAT 12 Spare part price

SERVICE service_id INT 6 PK Number that identifies the


service
service_description VARCHAR 200 Service Description
number_of_hours INT 3 Number of hours of service
date_time_vehicle_entry DATETIME Quantity of spare parts
employee_id INT 6 FK Number that identifies the
employee
plate VARCHAR 6 FK Car plate
SPARE PARTS- spare_id INT 6 FK Number that identifies the spare
SERVICE part reference
service_id INT 6 FK Number that identifies the
service
amount INT 6 Physical quantity of the spare
part
unit_price FLOAT 12 Unit price of the spare part
registration_date DATETIME Date on which the spare part is
added to the service
invoice_id INT 6 PK Number that identifies the
invoice
BILL generation_date DATETIME Invoice date
spare_value FLOAT 12 Spare parts price
service_hour_value FLOAT 12 Price of service hours
VAT_percentage FLOAT 2 Tax to be applied
service_id INT 6 FK Number that identifies the
service

Restrictions

The following restrictions have been established that arise from the execution of the process.

Table2 Restrictions

Restricción en la base de datos


Un número de cedula solo puede identificar a una persona
Una persona solo puede tener un id de cliente
Una persona solo puede tener un id de empleado
Una placa solo puede identificar un solo vehículo
Un vehículo solo puede tener un id de cliente
Un repuesto solo puede tener un id de repuesto para una referencia
Para crear un servicio debe ingresar un vehículo al servicio
Un servicio no puede tener mas de un id de factura
Para crear una factura debe existir un servicio
La descripción de un servicio no puede ser nulo
Los valores de las fechas debe contener fecha y hora
Las cantidades se deben ingresar en valores enteros
El valor a indicar como porcentaje del iva se debe ingresar con números enteros 16 ó 19
Los valores calculados por subtotales de repuestos y horas de servicio técnico se almacenan antes
El valor total de la factura no se almacena, su valor es resultado de sumar los valores de horas y el
valor de los repuestos, mas el calculo del porcentaje del IVA
Physical Model

The physical model of the activity, designed in My SQL, and the SQL scripts with which it was

created are described below.


SQL scripts exported from My SQL:

-- MySQL Script generated by MySQL Workbench


-- Sat Dec 7 06:51:54 2019
--Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;


SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE,
SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DAT
E,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

-- -----------------------------------------------------
-- Schema mydb
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET utf8 ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`PERSON`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`PERSONA` (
`ID` INT NOT NULL,
`names` VARCHAR(45) NULL,
`last_name_1` VARCHAR(45) NULL,
`last_name_2` VARCHAR(45) NULL,
PRIMARY KEY (`ID`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`CLIENT`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`CLIENT` (
`client_id` INT NOT NULL,
`address` VARCHAR(120) NULL,
`landline` VARCHAR(45) NULL,
`mobile_phone` VARCHAR(45) NULL,
`PERSONA_cedula` INT NOT NULL,
PRIMARY KEY (`client_id`, `PERSON_ID`),
INDEX `fk_CLIENTE_PERSONA1_idx` (`PERSONA_cedula` ASC) VISIBLE,
CONSTRAINT `fk_CLIENT_PERSONA1`
FOREIGN KEY (`PERSONA_cedula`)
REFERENCES `mydb`.`PERSONA` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`VEHICLE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`VEHICLE` (
`plate` VARCHAR(6) NOT NULL,
`model` VARCHAR(45) NULL,
`color` VARCHAR(45) NULL,
`brand` VARCHAR(45) NULL,
`CLIENTE_client_id` INT NOT NULL,
PRIMARY KEY (`board`, `CUSTOMER_customer_id`),
INDEX `fk_VEHICULO_CLIENTE1_idx` (`CUSTOMER_id_customer` ASC) VISIBLE,
CONSTRAINT `fk_VEHICLE_CUSTOMER1`
FOREIGN KEY (`CLIENTE_client_id`)
REFERENCES `mydb`.`CLIENTE` (`client_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`EMPLOYEE_STATUS`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`EMPLOYEE_STATUS` (
`id_state` INT NOT NULL,
`status_description` VARCHAR(45) NULL,
PRIMARY KEY (`id_estado`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`EMPLOYEE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`EMPLOYEE` (
`employee_id` INT NOT NULL,
`PERSONA_cedula` INT NOT NULL,
`EMPLOYEE_STATUS_status_id` INT NOT NULL,
PRIMARY KEY (`employee_id`, `PERSON_ID`, `EMPLOYEE_STATUS_status_id`),
INDEX `fk_EMPLOYEE_PERSON1_idx` (`PERSON_ID` ASC) VISIBLE,
INDEX `fk_EMPLOYEE_STATUS_EMPLOYEE1_idx` (`EMPLOYEE_STATUS_status_id` ASC) VISIBLE,
CONSTRAINT `fk_EMPLOYEE_PERSON1`
FOREIGN KEY (`PERSONA_cedula`)
REFERENCES `mydb`.`PERSONA` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_EMPLOYEE_STATUS_EMPLOYEE1`
FOREIGN KEY (`EMPLOYEE_STATE_status_id`)
REFERENCES `mydb`.`EMPLOYEE_STATUS` (`status_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`SPARE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`SPARE` (
`spare_id` INT NOT NULL,
`reference` VARCHAR(45) NULL,
`spare_description` VARCHAR(200) NULL,
`spare_brand` VARCHAR(45) NULL,
`price` FLOAT NULL,
PRIMARY KEY (`spare_id`))
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`SERVICE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`SERVICE` (
`service_id` INT NOT NULL,
`service_description` VARCHAR(200) NULL,
`number_of_hours` INT NULL,
`vehicle_entry_datetime` DATETIME NULL,
`EMPLOYEE_employee_id` INT NOT NULL,
`VEHICLE_LICENSE_PLATE` VARCHAR(6) NOT NULL,
PRIMARY KEY (`service_id`, `EMPLOYEE_employee_id`, `VEHICLE_plate`),
INDEX `fk_SERVICIO_EMPLEADO1_idx` (`EMPLOYEE_employee_id` ASC) VISIBLE,
INDEX `fk_SERVICIO_VEHICULO1_idx` (`VEHICULO_placa` ASC) VISIBLE,
CONSTRAINT `fk_EMPLOYEE_SERVICE1`
FOREIGN KEY (`EMPLOYEE_employee_id`)
REFERENCES `mydb`.`EMPLOYEE` (`employee_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_VEHICLE_SERVICE1`
FOREIGN KEY (`VEHICLE_LICENSE_PLATE`)
REFERENCES `mydb`.`VEHICLE` (`license plate`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`INVOICE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`INVOICE` (
`invoice_id` INT NOT NULL,
`fact_date` DATETIME NULL,
`spare_value` FLOAT NULL,
`service_hour_value` FLOAT NULL,
`subtotal_fact` FLOAT NULL,
`tax` FLOAT NULL,
`total_fact` FLOAT NULL,
`SERVICE_service_id` INT NOT NULL,
PRIMARY KEY (`invoice_id`, `SERVICE_service_id`),
INDEX `fk_FACTURA_SERVICIO1_idx` (`SERVICIO_id_servicio` ASC) VISIBLE,
CONSTRAINT `fk_INVOICE_SERVICE1`
FOREIGN KEY (`SERVICE_service_id`)
REFERENCES `mydb`.`SERVICE` (`service_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`table1`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`table1` (
)
ENGINE = InnoDB;

-- -----------------------------------------------------
-- Table `mydb`.`SERVICE_has_SPARE`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`SERVICIO_has_REPUESTO` (
`SERVICE_service_id` INT NOT NULL,
`SPARE_ID_spare` INT NOT NULL,
PRIMARY KEY (`SERVICE_service_id`, `SPARE_PART_spare_id`),
INDEX `fk_SERVICIO_has_REPUESTO_REPUESTO1_idx` (`REPUESTO_id_repuesto` ASC) VISIBLE,
INDEX `fk_SERVICIO_has_REPUESTO_SERVICIO1_idx` (`SERVICIO_id_servicio` ASC) VISIBLE,
CONSTRAINT `fk_SERVICE_has_SPARE_SERVICE1`
FOREIGN KEY (`SERVICE_service_id`)
REFERENCES `mydb`.`SERVICE` (`service_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_SERVICE_has_SPARE_PART_SPARE1`
FOREIGN KEY (`SPARE_id_repuesto`)
REFERENCES `mydb`.`SPARE` (`spare_id`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;

SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
Activity 2 Approach

Establish and write functions, procedures, cursors and triggers relevant to the proposed

case. Also, indicate how you can ensure ACID properties.

The activity was developed in Oracle, with the user as owner of the schema, tables,

public synonyms, sequences, procedures, functions, among these is the use of cursors, and also

the implementation of triggers in the management of the key fields of each table.

The SQL codes used in the development of this activity are listed below.

o Creating users and connection permissions

--Creating the user


CREATE USER house2car IDENTIFIED BY house2car;
--Connection permission
GRANT CONNECT TO house2car;

o Creating tables and triggers for handling incremental sequences

/*CREATION OF TABLES*/
CREATE TABLE STATE(
STATUS_ID NUMBER(3,0) PRIMARY KEY,
DESCRIPTION_EST VARCHAR2(60));

CREATE PUBLIC SYNONYM state FOR house2car.state;

CREATE SEQUENCE SQ_ID_ESTADO


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

CREATE TABLE PERSON(


ID VARCHAR2(20) PRIMARY KEY,
VARCHAR2(45) NAMES,
LAST NAME1 VARCHAR2(45),
LAST NAME2 VARCHAR2(45));
CREATE PUBLIC SYNONYM PERSON FOR house2car.PERSONA;

CREATE TABLE CUSTOMER(


CUSTOMER_ID NUMBER(9,0) PRIMARY KEY,
VARCHAR2(20) CEDULA,
ADDRESS VARCHAR2(100),
MOBILE_PHONE VARCHAR2(20),
LANDLINE_PHONE VARCHAR2(20),
CONSTRAINT PER_CLIENTE FOREIGN KEY (ID card) REFERENCES person(ID card));

CREATE PUBLIC SYNONYM CLIENTE FOR HOUSE2CAR.CLIENTE;

CREATE SEQUENCE SQ_ID_CUSTOMER


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

CREATE OR REPLACE TRIGGER CLIENTE_SEQ_TRIGGER


BEFORE INSERT ON CLIENT
FOR EACH ROW
BEGIN
IF :new.client_id IS NULL THEN
SELECT SQ_CUSTOMER_ID.nextval INTO :new.customer_id FROM DUAL;
END IF;
END;

CREATE TABLE EMPLOYEE(


EMPLOYEE_ID NUMBER(9,0) PRIMARY KEY,
VARCHAR2(20) CEDULA,
ID_STATUS NUMBER(3,0),
CONSTRAINT PER_EMPLEADO FOREIGN KEY (ID card) REFERENCES person(ID card),
CONSTRAINT EST_EMPLEADO FOREIGN KEY (id_estado) REFERENCES estado(id_estado));

CREATE PUBLIC SYNONYM EMPLOYEE FOR HOUSE2CAR.EMPLOYEE;

CREATE SEQUENCE SQ_EMPLOYEE_ID


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

CREATE OR REPLACE TRIGGER EMPLOYEE_SEQ_TRIGGER


BEFORE INSERT ON EMPLOYEE
FOR EACH ROW
BEGIN
IF :new.employeeid IS NULL THEN
SELECT SQ_EMPLOYEE_ID.nextval INTO :new.employee_id FROM DUAL;
END IF;
END;
CREATE TABLE VEHICLE(
VARCHAR2(12) PRIMARY KEY PLATE,
CLIENT_ID NUMBER(9,0),
MODEL NUMBER(4),
COLOR VARCHAR2(20),
VARCHAR2(30) BRAND,
CONSTRAINT CLI_VEHICULO FOREIGN KEY (CUSTOMER_ID) CUSTOMER REFERENCES
(CUSTOMER_ID));

CREATE PUBLIC SYNONYM VEHICULO FOR HOUSE2CAR.VEHICULO;

CREATE TABLE SERVICE(


ID_SERVICE NUMBER(9,0) PRIMARY KEY,
CLIENT_ID NUMBER(9,0),
VARCHAR2(12) PLATE,
EMPLOYEE_ID NUMBER(9,0),
DESCRIPTION VARCHAR2(300),
DATETIME_LOGIN DATE,
QUANTITY_HOURS NUMBER(3),
CONSTRAINT CLI_SERVICIO FOREIGN KEY (CUSTOMER_ID) CUSTOMER
REFERENCES(CUSTOMER_ID),
CONSTRAINT VEH_SERVICIO FOREIGN KEY (PLATE) REFERENCES VEHICLE(PLATE),
CONSTRAINT EMP_SERVICIO FOREIGN KEY (EMPLOYEE_ID) REFERENCES
EMPLOYEE(EMPLOYEE_ID));

CREATE PUBLIC SYNONYM SERVICIO FOR HOUSE2CAR.SERVICE;

CREATE SEQUENCE SQ_SERVICE_ID


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

CREATE OR REPLACE TRIGGER SERVICE_SEQ_TRIGGER


BEFORE INSERT ON SERVICE
FOR EACH ROW
BEGIN
IF :new.service_id IS NULL THEN
SELECT SQ_SERVICE_ID.nextval INTO :new.service_id FROM DUAL;
END IF;
END;

CREATE TABLE INVOICE(


INVOICE_ID NUMBER(9,0) PRIMARY KEY,
SERVICE_ID NUMBER(9,0),
GENERATION_DATE DATE,
SERVICE_TIME_VALUE NUMBER(9,3),
SPARE_VALUE NUMBER(9,3),
PERCENTAGE_VAT NUMBER(3,0),
CONSTRAINT SER_FACTURA FOREIGN KEY (SERVICE_ID) REFERENCES
SERVICE(SERVICE_ID));
CREATE PUBLIC SYNONYM INVOICE FOR HOUSE2CAR.INVOICE;

CREATE SEQUENCE SQ_ID_INVOICE


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

CREATE OR REPLACE TRIGGER INVOICE_SEQ_TRIGGER


BEFORE INSERT ON INVOICE
FOR EACH ROW
BEGIN
IF :new.factura_id IS NULL THEN
SELECT SQ_INVOICE_ID.nextval INTO :new.invoice_id FROM DUAL;
END IF;
END;

CREATE TABLE SPARE(


SPARE_ID NUMBER(9,0) PRIMARY KEY,
REFERENCE VARCHAR(100),
DESCRIPTION VARCHAR(300),
VARCHAR2(80) BRAND,
PRICE NUMBER(9,3));

CREATE PUBLIC SYNONYM REPEUESTO FOR HOUSE2CAR.REPEUESTO;

CREATE SEQUENCE SQ_ID_REPUESTO


START WITH 1
INCREMENT BY 1
NOCACHE
NOCYCLE;

CREATE OR REPLACE TRIGGER REPUESTO_SEQ_TRIGGER


BEFORE INSERT ON SPARE PART
FOR EACH ROW
BEGIN
IF :new.spare_id IS NULL THEN
SELECT SQ_ID_REPUESTO.nextval INTO :new.id_repuesto FROM DUAL;
END IF;
END;

CREATE TABLE SPARE_SERVICE(


SERVICE_ID NUMBER(9,0),
ID_REPUESTO NUMBER(9,0),
QUANTITY NUMBER(3,0),
UNIT_PRICE NUMBER(9,3),
DATE_REGISTRATION DATE,
CONSTRAINT SER_REPUESTO UNIQUE (SERVICE_ID, SPARE_ID),
CONSTRAINT REP_SERVICIO FOREIGN KEY (ID_REPUESTO) REFERENCES
REPUESTO(ID_REPUESTO));

CREATE PUBLIC SYNONYM SPARE_SERVICE FOR HOUSE2CAR.SPARE_SERVICE;


o Invoice generation procedure

CREATE OR REPLACE PROCEDURE GENERAR_INVOICE (pi_serviceid NUMBER, pi_valuexhour


NUMBER)IS
l_existe_servicio NUMBER(9) := EXIST_SERVICE(pi_idservicio);
l_total_spare_parts NUMBER(9,3);
l_total_hours NUMBER(9,3);
l_total_iva NUMBER(9,3);
l_porcentajeiva NUMBER(2) := 19; --Percentage of 19% VAT
BEGIN
IF (l_existe_servicio > 0 AND pi_valorxhora > 0) THEN
--The value of the service spare parts is calculated
SELECT SUM(quantity*unit_price)
INTO l_total_spare_parts
FROM service_spare
WHERE service_id = pi_service_id;

SELECT (((hour_count * pi_hour_value)+ l_total_spare_parts)* l_percentageiva)/100,


(hours_count * pi_hour_value)
INTO l_total_iva, l_total_hours
FROM service
WHERE service_id = pi_service_id;

IF l_total_spares > 0 OR l_total_hours > 0 THEN


INSERT INTO INVOICE
VALUES(null,
pi_idservicio,
SYSDATE(),
l_total_hours,
l_total_spare_parts,
l_percentageiva);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Spare part assigned to service successfully');
END IF;
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Generating service invoice'||pi_idservicio);
END GENERATE_INVOICE;
o Procedure for creating spare parts

CREATE OR REPLACE PROCEDURE CREATE_SPARE_PART (pi_reference VARCHAR2, pi_description


VARCHAR2, pi_brand VARCHAR2,
pi_precio NUMBER)IS
l_existe_refrepuesto VARCHAR2(20) := EXISTE_REFREPUESTO(pi_referencia, pi_marca);

BEGIN
IF (l_existe_frefrepuesto = 0 AND pi_reference IS NOT NULL AND pi_brand IS NOT NULL)
THEN
INSERT INTO SPARE PART
VALUES(NULL,
pi_reference,
pi_description,
pi_marca,
pi_price);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Spare part created successfully');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('The spare part already exists: '||l_existe_refrepuesto||', reference: '||
pi_referencia||' and brand: '||pi_marca);
END IF;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Spare part with reference'||pi_referencia);
END CREATE_SPARE;

o Procedure for assigning spare parts to the service.

CREATE OR REPLACE PROCEDURE ASIGREP_SERVICIO (pi_serviceid NUMBER, pi_replacement


NUMBER, pi_quantidad NUMBER,
pi_unitprice NUMBER, pi_employeeid NUMBER)IS
l_existe_servicio NUMBER(9) := EXIST_SERVICE(pi_idservicio);
l_existe_repuesto NUMBER(9,0) := EXIST_REPUESTO(pi_idrepuesto);
l_authorized_employee CHAR(1) := EMPASIG_SERVICE(pi_idservice, pi_idempleado);
BEGIN
IF (l_existe_servicio > 0 AND l_existe_repuesto > 0 AND l_empleado_autorizado = 'A' AND
pi_cantidad > 0
AND unit_price pi > 0 AND employee_id pi IS NOT NULL) THEN
DBMS_OUTPUT.PUT_LINE('Service exists: '||pi_idservicio||' assigned employee and/or person in
charge: '||pi_idempleado);
INSERT INTO SERVICE_SPARE
VALUES(pi_idservicio,
pi_idrepuesto,
pi_amount,
pi_unitprice,
SYSDATE());
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Spare part assigned to service successfully');
END IF;
ELSIF l_authorized_employee = 'N' THEN
DBMS_OUTPUT.PUT_LINE('Employee is not authorized: '||pi_idempleado|| ' to assign spare parts to
the service: '||pi_idservicio);
ELSE
DBMS_OUTPUT.PUT_LINE('The service does not exist: '||l_existe_servicio||' or the spare part does
not exist'||l_existe_repuesto);
END IF;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Updating spare'||pi_idrepuesto||' to service:'||
pi_idservicio);
END ASIGREP_SERVICE;

o Procedure for assigning employees to the service

CREATE OR REPLACE PROCEDURE ASIGEMP_SERVICIO (pi_service_id NUMBER, pi_employee


NUMBER, p_operacion CHAR)IS
l_employee_status NUMBER(9,0) := EMPLOYEE_STATUS(pi_iemployee);
l_existe_servicio VARCHAR2(12) := EXIST_SERVICE(pi_idservicio);
BEGIN
IF (l_existe_servicio > 0 AND l_estado_empleado = 2 AND p_operacion = 'A') THEN
DBMS_OUTPUT.PUT_LINE('Service exists: '||pi_idservicio||' and employee exists: '||pi_idempleado||'
available status');
UPDATE SERVICE
SET employee_id = pi_employee_id
WHERE id_servicio = pi_idservicio
AND employee_id = 0;

DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Employee assigned to service successfully');
END IF;
ELSIF l_employee_status = 1 THEN
DBMS_OUTPUT.PUT_LINE('Employee is not available: '||pi_idempleado);
ELSIF p_operacion = 'R' THEN --Remove employee
UPDATE SERVICE
SET employee_id = 0
WHERE id_servicio = pi_idservicio
AND employee_id = pi_employed_id;
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Retired employee: '||pi_idempleado ||' from service: '||pi_idservicio);
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('The client does not exist: '||pi_idempleado||' or the service does not
exist'||pi_idservicio);
END IF;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Updating employee'||pi_idempleado||' to service:'||
pi_idservicio);
END ASIGEMP_SERVICE;

o Service Creation Procedure

CREATE OR REPLACE PROCEDURE CREATION_SERVICE (pi_idcliente NUMBER, pi_placa


VARCHAR2,
pi_idempleado NUMBER, pi_description VARCHAR2, pi_quantity_hours NUMBER)IS
l_existe_cliente NUMBER(9,0) := EXIST_CLIENTE(pi_idcliente);
l_existe_empleado NUMBER(9,0) := EXIST_PERSON(pi_idempleado);
l_existe_vehiculo VARCHAR2(12) := EXIST_VEHICULO(pi_placa);
l_idservicio NUMBER(9);
BEGIN
IF l_existe_cliente > 0 AND LENGTH(l_existe_vehiculo) > 0
THEN
DBMS_OUTPUT.PUT_LINE('Client exists: '||pi_idcliente||' and vehicle exists: '||pi_placa);
INSERT INTO SERVICE
VALUES(null,
pi_idclient,
pi_plate,
NVL(pi_idempleado,0), --In case the field arrives null
pi_description,
sysdate(),
pi_amount_hours);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Service created successfully');
IF EMPLOYEE_STATUS(pi_iemployed) = 2 THEN
l_idservicio := TRAE_SERVICIO(pi_idcliente, pi_placa);
IF l_idservicio > 0 THEN
ASIGEMP_SERVICIO(l_idservicio,pi_idempleado,'R'); --The employee is withdrawn due to
unavailability
END IF;
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred creating the service');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('The client does not exist: '||pi_idcliente||' or the vehicle does not exist'||
pi_placa);
END IF;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Service'||pi_idcliente||' Vehicle:'||pi_placa);
END CREATION_SERVICE;

o Vehicle creation procedure.

CREATE OR REPLACE PROCEDURE CREATION_VEHICLE (pi_plate VARCHAR2,pi_idcliente


NUMBER, pi_model NUMBER,
pi_color VARCHAR2, pi_brand VARCHAR2)IS
l_existe_vehiculo VARCHAR2(12) := EXIST_VEHICULO(pi_placa);
l_existe_cliente NUMBER(9,0) := EXIST_CLIENTE(pi_idcliente);
BEGIN
IF l_existe_vehiculo = 0 AND LENGTH(l_existe_cliente) > 0
THEN
DBMS_OUTPUT.PUT_LINE('There is a client and the vehicle does not exist: '||pi_plate);
INSERT INTO VEHICLE
VALUES(pi_plate,
pi_idclient,
pi_model,
pi_color,
pi_marca);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Vehicle created successfully');
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred while creating the vehicle');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('Does a vehicle exist?: '||pi_plate);
DBMS_OUTPUT.PUT_LINE('Client does not exist?: '||pi_idcliente);
END IF;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Vehicle'||pi_plate);
END CREATION_VEHICLE;

o Procedure for creating employees.

CREATE OR REPLACE PROCEDURE CREATE_EMPLOYEE(pi_cedula VARCHAR2,pi_nombres


VARCHAR2, pi_apellido1 VARCHAR2,
pi_last_name2 VARCHAR2, pi_STATE NUMBER)IS
l_existe_persona VARCHAR2(20) := EXIST_PERSON(pi_cedula);

BEGIN
IF LENGTH(l_exists_person) > 0
THEN
DBMS_OUTPUT.PUT_LINE('The person exists: '||l_existe_persona);
INSERT INTO EMPLOYEE(ID,state_id)
VALUES(pi_cedula,pi_estado);
ELSE
DBMS_OUTPUT.PUT_LINE('The person does not exist: '||pi_cedula);
DBMS_OUTPUT.PUT_LINE('Data: '||pi_cedula||' It is being created.');
INSERT INTO PERSON
VALUES(pi_cedula,
pi_names,
pi_lastname1,
pi_lastname2);
IF SQL%ROWCOUNT=1 THEN
COMMIT;
INSERT INTO EMPLOYEE(ID,state_id)
VALUES(pi_cedula,pi_estado);
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Person and employee created:'|| pi_cedula);
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred creating the employee');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred creating the person');
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Employee Creation'||pi_cedula);
END CREATE_EMPLOYEE;

o Procedure for creating people.

CREATE OR REPLACE PROCEDURE CREATION_PERSON (pi_cedula VARCHAR2,pi_nombres


VARCHAR2, pi_apellido1 VARCHAR2,
pi_lastname2 VARCHAR2)IS
l_existe_persona VARCHAR2(20) := EXIST_PERSON(pi_cedula);
l_sq_attendance_id NUMBER(5,0);
l_id_asistencia NUMBER(5,0);
c_attendance_id NUMBER(5,0) := 1000;
BEGIN
IF LENGTH(l_exists_person) > 0
THEN
DBMS_OUTPUT.PUT_LINE('There is a person with the ID: '||pi_cedula);
ELSE
DBMS_OUTPUT.PUT_LINE('Data: '||pi_cedula||' '||sysdate);
INSERT INTO PERSON
VALUES(pi_cedula,
pi_names,
pi_lastname1,
pi_lastname2);
DBMS_OUTPUT.PUT_LINE(TO_CHAR(SQL%ROWCOUNT));
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Person created successfully');
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred creating the person');
END IF;
END IF;

EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Person'||pi_cedula);
END CREATION_PERSON;

o Client creation procedure

CREATE OR REPLACE PROCEDURE CREATE_CLIENTE(pi_cedula VARCHAR2,pi_nombres


VARCHAR2, pi_apellido1 VARCHAR2,
pi_last_name2 VARCHAR2, pi_address VARCHAR2, pi_mobile_phone VARCHAR2,
pi_landline_phone VARCHAR2)IS
l_existe_persona VARCHAR2(20) := EXIST_PERSON(pi_cedula);

BEGIN
IF LENGTH(l_exists_person) > 0
THEN
DBMS_OUTPUT.PUT_LINE('The person exists: '||l_existe_persona);
INSERT INTO CUSTOMER(ID,address,mobile_phone,landline_phone)
VALUES(pi_cedula,pi_direccion,pi_telefono_movil,pi_telefono_fired);
ELSE
DBMS_OUTPUT.PUT_LINE('The person does not exist: '||pi_cedula);
DBMS_OUTPUT.PUT_LINE('Data: '||pi_cedula||' It is being created.');
INSERT INTO PERSON
VALUES(pi_cedula,
pi_names,
pi_lastname1,
pi_lastname2);
IF SQL%ROWCOUNT=1 THEN
COMMIT;
INSERT INTO CUSTOMER(ID,address,mobile_phone,landline_phone)
VALUES(pi_cedula,pi_direccion,pi_telefono_movil,pi_telefono_fired);
IF SQL%ROWCOUNT=1 THEN
COMMIT;
DBMS_OUTPUT.PUT_LINE('Person and client created:'|| pi_cedula);
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred creating the client');
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('An error occurred creating the person');
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR(-20000,'Error: Creating Client'||pi_cedula);
END CREATE_CLIENT;

o Data display function

CREATE OR REPLACE FUNCTION VER_SERVICIOSEMPLEADO (pi_employee


NUMBER)RETURN sys_refcursor
ACE
vEmployeeServices SYS_REFCURSOR;
BEGIN
OPEN vServicesEmployee FOR
SELECT s.id_service, s.id_customer, c.ID customer_ID, c.address, c.mobile_phone,
f. invoice_id, f. service_hour_value, f. spare_parts_value, (f. service_hour_value+f.
spare_parts_value)*f. percentage_vat/100 total_vat,
s.vehicle plate, s.employee_id, e.ID card employee_ID
FROM service s,
invoice f,
client c,
employee and
WHERE
s.id_service = f.id_service
AND s.customer_id = c.customer_id
AND s.employee_id = e.employee_id
AND s.employee_id = pi_employee_id;
RETURN vEmployeeServices;
END SEE_EMPLOYEESERVICES;

o Check functions

CREATE OR REPLACE FUNCTION EMPASIG_SERVICIO(pi_serviceid NUMBER,pi_employee


NUMBER)
RETURN CHAR IS
l_authorized CHAR(1);
BEGIN
IF (pi_serviceid IS NOT NULL AND pi_employee IS NOT NULL) THEN
SELECT 'A'
INTO l_authorized
FROM service
WHERE id_servicio = pi_idservicio
AND employee_id = pi_employed_id;
END IF;
RETURN l_authorized;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 'N';
END EMPASIG_SERVICE;

CREATE OR REPLACE FUNCTION EXISTE_REFREPUESTO(pi_referencia VARCHAR2, pi_marca


VARCHAR2)
RETURN NUMBER IS
l_idrepuesto NUMBER(9);
BEGIN
IF (reference_pi IS NOT NULL AND brand_pi IS NOT NULL) THEN
SELECT spare_id
INTO l_idrepuesto
FROM spare part
WHERE reference = pi_referencia
AND brand = pi_brand;
END IF;
RETURN l_idrepuesto;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXISTS_REFRESHED;

CREATE OR REPLACE FUNCTION TRAE_SERVICIO(pi_idcliente NUMBER, pi_placa VARCHAR2)


RETURN NUMBER IS
l_idservicio NUMBER(3,0);
BEGIN
IF (pi_clienteID IS NOT NULL AND pi_plate IS NOT NULL) THEN
SELECT service_id
INTO l_idservicio
FROM service
WHERE customer_id = customer_id pi
AND plate = pi_plate;
END IF;
RETURN l_idservicio;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END BRING_SERVICE;

CREATE OR REPLACE FUNCTION EMPLOYEE_STATUS(pi_iemployee NUMBER)


RETURN NUMBER IS
l_employee_status NUMBER(3,0);
BEGIN
IF (pi_idemployee IS NOT NULL) THEN
SELECT state_id
INTO l_employee_status
FROM employee
WHERE employee_id = pi_employee;
END IF;
RETURN l_employee_status;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EMPLOYEE_STATUS;

CREATE OR REPLACE FUNCTION EXIST_SERVICIO(pi_serviceid VARCHAR2)


RETURN NUMBER IS
l_idservicio NUMBER(9);
BEGIN
IF (pi_serviceid IS NOT NULL) THEN
SELECT service_id
INTO l_idservicio
FROM service
WHERE id_service = pi_idservice;
END IF;
RETURN l_idservicio;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXIST_SERVICE;

CREATE OR REPLACE FUNCTION EXIST_REPUESTO(pi_idrepuesto VARCHAR2)


RETURN NUMBER IS
l_idrepuesto NUMBER(9);
BEGIN
IF (pi_spareid IS NOT NULL) THEN
SELECT spare_id
INTO l_idrepuesto
FROM spare part
WHERE spare_id = pi_spare_id;
END IF;
RETURN l_idrepuesto;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXIST_SPARE;

CREATE OR REPLACE FUNCTION EXIST_EMPLEADO(pi_idemployee VARCHAR2)


RETURN NUMBER IS
l_idempleado NUMBER(9);
BEGIN
IF (pi_idemployee IS NOT NULL) THEN
SELECT employee_id
INTO l_idempleado
FROM employee
WHERE employee_id = employee_id;
END IF;
RETURN l_unemployed;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXIST_EMPLOYEE;

CREATE OR REPLACE FUNCTION EXIST_CLIENTE(pi_clienteid VARCHAR2)


RETURN NUMBER IS
l_idcliente NUMBER(9);
BEGIN
IF (pi_clienteid IS NOT NULL) THEN
SELECT customer_id
INTO l_idcliente
FROM client
WHERE customer_id = customer_id;
END IF;
RETURN l_idcliente;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXIST_CUSTOMER;

CREATE OR REPLACE FUNCTION EXIST_VEHICULO(pi_plate VARCHAR2)


RETURN VARCHAR2 IS
l_plate VARCHAR2(12);
BEGIN
IF (pi_plate IS NOT NULL) THEN
SELECT plate
INTO l_plate
FROM vehicle
WHERE plate = pi_plate;
END IF;
RETURN l_plate;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXIST_VEHICLE;

CREATE OR REPLACE FUNCTION EXIST_PERSONA(pi_cedula VARCHAR2)


RETURN VARCHAR2 IS
l_cedula VARCHAR2(20);
BEGIN
IF (pi_cedula IS NOT NULL) THEN
SELECT ID
INTO l_cedula
FROM person
WHERE cedula = pi_cedula;
END IF;
RETURN l_cedula;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RETURN 0;
END EXIST_PERSON;

How to ensure ACID properties.

ACID is a group of 4 properties that ensure that database transactions are performed

reliably. Each of these properties and how they can be secured are described below.

o Atomicity: It is the property that guarantees and verifies whether the transaction was carried

out or not and this property indicates that if an operation is not completed then it is cancelled.

For example, when inserting a record and the server goes down, a record was recorded

halfway, then by atomicity this record will not be recorded.

Atomicity is usually implemented by some mechanism that indicates which transaction

started and which ended, or by maintaining a copy of the data before changes occur.

Databases generally implement atomicity by using some logging system to track changes.

The system synchronizes logs as needed once changes occur successfully. The crash

recovery system then simply ignores the incomplete entries.

o Consistency: It is the property that guarantees that transactions that can be completed

without problems will be executed. This concept has to do with the integrity of the database.

Prevents data from being changed and becoming meaningless or unreferenced. For example,

in our mechanical workshop activity, a customer cannot be deleted if they have used some

service of the workshop. If you want to delete the client, you will first have to delete all

invoices and data related to that client.


o Isolation: It is the property that guarantees that if two or more transactions occur at the same

time, they will be executed one after the other and if they are executed in parallel, each one

will do so independently of the other to avoid possible errors.

Most databases offer a number of transaction isolation levels, which control the degree of

locking that occurs when data is selected. For many applications, most transactions can be

constructed avoiding the higher isolation levels and thus reducing the load on the system due

to locks.

o Durability: This is the property that ensures that a transaction has been carried out and the

changes made by the transaction are permanent, even in the event of any problem such as

power outages or system failures.

Typically in databases, durability is implemented by writing transactions to a transaction log

that can be reprocessed to recreate the state of the system before a failure. A transaction is

considered confirmed only after it has been entered into the log.

Other good practices to ensure ACID properties are as follows:

o Make backups: Companies usually make backups of their databases every hour, day or

week, depending on the size of the database and the available space. When something bad
happens, you can import data from the old database for any tables that were damaged or lost.

The data may be a little out of date, but having outdated data is better than having no data.

o Do Replication: A related approach is replication: always store multiple copies of the

databases on different sides. If for some reason a particular copy of the database is not

available, then the query can be sent to another copy of the database that is available.

o Granting Privileges: Users and privileges need to be set up appropriately from the

beginning of database creation. As a general rule, there should only be a few users with full

access to the database (such as backend engineers), to reduce the risk of data loss and

database alterations due to inadvertent errors.

Literature

Database Fundamentals. Fourth edition; regarding the fourth edition in Spanish, by McGRAW-

HILL/INTERAMERICANA DE ESPAÑA, S. TO. OR.

http://www.mcgraw-hill.es/olc/silberschatz
Garcia-Molina 1983 H. García-Molina, Using Semantic Knowledge for Transaction Processing

in a Distributed Database, ACM Transactions on Database Systems, volume 8, number 2 (1983),

pages 186-213.

ACID Transactions and Referential Integrity. Retrieved from

https://www.solvetic.com/tutoriales/article/1955-mysql-realizar-transacciones-acid-e-integridad-

referencial/

ACID in databases. Retrieved from https://dosideas.com/noticias/base-de-datos/973-acid-en-las-

bases-de-datos

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy