SQLize
Online
/
PHPize Online
/
SQLtest Online
A
A
A
Share
Donate
Blog
Popular
Donate
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.
SQL code:
Upload
Copy
Format
Clear
-- Таблица пациентов CREATE TABLE t_tpatient ( tpatient_id NUMBER NOT NULL, patient_id NUMBER NOT NULL, firstname CLOB, lastname CLOB, secondname CLOB, databirth DATE, adress CLOB, pol CLOB, discounts NUMBER, valid_from TIMESTAMP, valid_to TIMESTAMP, transaction_time TIMESTAMP DEFAULT SYSTIMESTAMP, CONSTRAINT t_tpatient_pk PRIMARY KEY (tpatient_id, valid_from), CONSTRAINT t_tpatient_patientid_un UNIQUE (patient_id) ); -- Таблица врачей CREATE TABLE t_tdoctor ( tdoctor_id NUMBER NOT NULL, doctor_id NUMBER NOT NULL, firstname CLOB, lastname CLOB, secondname CLOB, speciality CLOB, category CLOB, valid_from TIMESTAMP, valid_to TIMESTAMP, transaction_time TIMESTAMP DEFAULT SYSTIMESTAMP, CONSTRAINT t_tdoctor_pk PRIMARY KEY (tdoctor_id, valid_from), CONSTRAINT t_tdoctor_doctorid_un UNIQUE (doctor_id) ); -- Таблица диагнозов CREATE TABLE t_diagnosis ( diagnosis_id NUMBER NOT NULL, iddiagnos NUMBER, namediagnos CLOB, diagnosiscode NUMBER, valid_from TIMESTAMP, valid_to TIMESTAMP, transaction_time TIMESTAMP DEFAULT SYSTIMESTAMP, CONSTRAINT t_diagnosis_pk PRIMARY KEY (diagnosis_id, valid_from), CONSTRAINT t_diagnosis_iddiagnos_un UNIQUE (iddiagnos) ); -- Таблица истории пациентов CREATE TABLE t_patient_history ( history_id NUMBER NOT NULL, tpatient_id NUMBER NOT NULL, idcart NUMBER, firstname CLOB, lastname CLOB, secondname CLOB, databirth DATE, adress CLOB, pol CLOB, discounts NUMBER, valid_from TIMESTAMP, valid_to TIMESTAMP, transaction_time TIMESTAMP DEFAULT SYSTIMESTAMP, CONSTRAINT t_patient_history_pk PRIMARY KEY (history_id, valid_from), CONSTRAINT t_patient_history_tpatient_fk FOREIGN KEY (tpatient_id, valid_from) REFERENCES t_tpatient (tpatient_id, valid_from) ); -- Таблица лечения CREATE TABLE t_treatment ( treatment_id NUMBER NOT NULL, tpatient_id NUMBER NOT NULL, tdoctor_id NUMBER NOT NULL, start_date DATE, end_date DATE, treatment_details CLOB, valid_from TIMESTAMP, valid_to TIMESTAMP, transaction_time TIMESTAMP DEFAULT SYSTIMESTAMP, CONSTRAINT t_treatment_pk PRIMARY KEY (treatment_id, valid_from), CONSTRAINT fk_t_treatment_patient FOREIGN KEY (tpatient_id, valid_from) REFERENCES t_tpatient (tpatient_id, valid_from), CONSTRAINT fk_t_treatment_doctor FOREIGN KEY (tdoctor_id, valid_from) REFERENCES t_tdoctor (tdoctor_id, valid_from) ); CREATE OR REPLACE PACKAGE treatment_pkg AS PROCEDURE check_existing_treatment(p_tpatient_id IN NUMBER); END treatment_pkg; / CREATE OR REPLACE PACKAGE BODY treatment_pkg AS PROCEDURE check_existing_treatment(p_tpatient_id IN NUMBER) IS l_count INTEGER; BEGIN SELECT COUNT(*) INTO l_count FROM t_treatment WHERE tpatient_id = p_tpatient_id AND valid_to > SYSDATE; IF l_count > 0 THEN RAISE_APPLICATION_ERROR(-20001, 'Existing treatment is still ongoing. Cannot add new treatment.'); END IF; END check_existing_treatment; END treatment_pkg; / CREATE OR REPLACE TRIGGER check_treatment_before_insert BEFORE INSERT ON t_treatment FOR EACH ROW BEGIN treatment_pkg.check_existing_treatment(:NEW.tpatient_id); END; /
SQL
Server:
MariaDB 11.4
MariaDB 11.5
MariaDB 10
MariaDB 10 Sakila (ReadOnly)
MySQL 5.7
MySQL 5.7 Sakila (ReadOnly)
MySQL 8.0
MySQL 8.0 Sakila (ReadOnly)
SQLite 3
PostgreSQL 10 Bookings (ReadOnly)
PostgreSQL 11
PostgreSQL 12
PostgreSQL 13
PostgreSQL 14
PostgreSQL 15
MS SQL Server 2017
MS SQL Server 2019
MS SQL Server 2022
MS SQL Server 2022 AdventureWorks (ReadOnly)
Firebird 4.0
Firebird 4.0 (Employee)
Oracle Database 19c (HR)
Oracle Database 21c
Oracle Database 23c Free
SOQOL
Version
ER Diagram
Preserve result
Stuck with a problem?
Got Error?
Ask ChatGPT!
Result:
Copy
Clear