Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Small script to create a sample database (Parking schema)
-- Create table ESTACIONAMIENTO
CREATE TABLE ESTACIONAMIENTO(
ID INT AUTO_INCREMENT PRIMARY_KEY,
NOMBRE VARCHAR(150),
COSTO_HORA INT NOT NULL,
COSTO_FRACCION INT NOT NULL
);
CREATE TABLE CAJON(
ID INT AUTO_INCREMENT PRIMARY_KEY,
OCUPADO BOOLEAN NOT NULL,
ID_ESTACIONAMIENTO INT NOT NULL,
FOREIGN KEY (ID_ESTACIONAMIENTO)
REFERENCES ESTACIONAMIENTO(ID)
ON DELETE CASCADE
);
CREATE TABLE TICKET(
ID INT AUTO_INCREMENT PRIMARY_KEY,
FOLIO VARCHAR(45) NOT NULL,
FECHA_ENTRADA DATETIME NOT NULL,
FECHA_SALIDA DATETIME,
COSTO DOUBLE,
PLACAS VARCHAR(25) NOT NULL,
MODELO VARCHAR(100),
ANIO INT,
ID_CAJON INT NOT NULL,
ID_ESTACIONAMIENTO INT NOT NULL,
FOREIGN KEY (ID_ESTACIONAMIENTO)
REFERENCES ESTACIONAMIENTO(ID)
ON DELETE CASCADE,
FOREIGN KEY (ID_CAJON)
REFERENCES CAJON(ID)
ON DELETE CASCADE
);
CREATE TABLE ROL(
ID INT AUTO_INCREMENT PRIMARY_KEY,
ROL VARCHAR(100) NOT NULL
);
CREATE TABLE USUARIO(
ID INT AUTO_INCREMENT PRIMARY_KEY,
NOMBRE VARCHAR(150) NOT NULL,
AP_PATERNO VARCHAR(100) NOT NULL,
AP_MATERNO VARCHAR(100),
ID_ESTACIONAMIENTO INT NOT NULL,
ID_ROL INT NOT NULL,
FOREIGN KEY (ID_ESTACIONAMIENTO)
REFERENCES ESTACIONAMIENTO(ID)
ON DELETE CASCADE,
FOREIGN KEY (ID_ROL)
REFERENCES ROL(ID)
ON DELETE CASCADE
);
CREATE TABLE CREDENCIAL(
ID INT AUTO_INCREMENT PRIMARY_KEY,
USERNAME VARCHAR(200) NOT NULL,
PASSWORD VARCHAR(5000) NOT NULL,
ID_USUARIO INT NOT NULL,
FOREIGN KEY (ID_USUARIO)
REFERENCES USUARIO(ID)
ON DELETE CASCADE
);
-- End tables creation
--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment