Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular

SQLize.online is a free online SQL environment for quickly running, experimenting with and sharing code. You can run your SQL code on top of the most popular RDBMS including MySQL, MariaDB, SQLite, PostgreSQL, Oracle and Microsoft SQL Server.

Copy Format Clear
-- Trabajadores CREATE TABLE Trabajadores ( ID_trabajador INT PRIMARY KEY AUTO_INCREMENT, Nombre VARCHAR(50) NOT NULL, Apellido VARCHAR(50) NOT NULL, RUT VARCHAR(12) NOT NULL UNIQUE, Cargo VARCHAR(50) NOT NULL, Empresa VARCHAR(50) NOT NULL, Fecha_contratación DATE NOT NULL, Supervisor INT, FOREIGN KEY (Supervisor) REFERENCES Trabajadores(ID_trabajador) ); -- Vacaciones CREATE TABLE Vacaciones ( ID_vacaciones INT PRIMARY KEY AUTO_INCREMENT, ID_trabajador INT NOT NULL, Fecha_inicio DATE NOT NULL, Fecha_fin DATE NOT NULL, Días_vacaciones INT GENERATED ALWAYS AS (DATEDIFF(Fecha_fin, Fecha_inicio) + 1), Estado_solicitud VARCHAR(20) DEFAULT 'En Espera', Comentarios TEXT, FOREIGN KEY (ID_trabajador) REFERENCES Trabajadores(ID_trabajador) ); -- Asistencia CREATE TABLE Asistencia ( ID_asistencia INT PRIMARY KEY AUTO_INCREMENT, ID_trabajador INT NOT NULL, Fecha DATE NOT NULL, Tipo_asistencia VARCHAR(20) CHECK (Tipo_asistencia IN ('Presente', 'Fallas', 'Vacaciones', 'Permiso', 'Licencia')), FOREIGN KEY (ID_trabajador) REFERENCES Trabajadores(ID_trabajador) ); -- Políticas de Vacaciones CREATE TABLE Políticas_Vacaciones ( ID_política INT PRIMARY KEY AUTO_INCREMENT, Cargo VARCHAR(50) NOT NULL, Años_experiencia_min INT NOT NULL, Años_experiencia_max INT NOT NULL, Días_vacaciones_anuales INT NOT NULL ); -- Aprobaciones CREATE TABLE Aprobaciones ( ID_aprobacion INT PRIMARY KEY AUTO_INCREMENT, ID_vacaciones INT NOT NULL, Fecha_solicitud DATE NOT NULL, Fecha_aprobacion DATE, Aprobado_por INT, Estado VARCHAR(20) DEFAULT 'En Espera', FOREIGN KEY (ID_vacaciones) REFERENCES Vacaciones(ID_vacaciones), FOREIGN KEY (Aprobado_por) REFERENCES Trabajadores(ID_trabajador) ); -- Tipos de Ausencias CREATE TABLE Tipos_Ausencias ( ID_tipo_ausencia INT PRIMARY KEY AUTO_INCREMENT, Descripción VARCHAR(50) NOT NULL, Código_tipo VARCHAR(10) NOT NULL UNIQUE ); -- Historial de Vacaciones Acumuladas CREATE TABLE Historial_Vacaciones_Acumuladas ( ID_historial INT PRIMARY KEY AUTO_INCREMENT, ID_trabajador INT NOT NULL, Año YEAR NOT NULL, Días_acumulados INT NOT NULL, Días_utilizados INT DEFAULT 0, Días_restantes INT GENERATED ALWAYS AS (Días_acumulados - Días_utilizados), FOREIGN KEY (ID_trabajador) REFERENCES Trabajadores(ID_trabajador) );

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear