Changes between Initial Version and Version 1 of ddlScript.sql


Ignore:
Timestamp:
01/20/25 18:21:13 (10 days ago)
Author:
221028
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ddlScript.sql

    v1 v1  
     1{{{#!sql
     2DROP TABLE IF EXISTS ExperimentLabEquipment CASCADE;
     3DROP TABLE IF EXISTS Experiment CASCADE;
     4DROP TABLE IF EXISTS Reaction CASCADE;
     5DROP TABLE IF EXISTS Elements CASCADE;
     6DROP TABLE IF EXISTS LabEquipment CASCADE;
     7DROP TABLE IF EXISTS USER CASCADE;
     8
     9
     10CREATE TABLE USER (
     11    user_id SERIAL PRIMARY KEY,
     12    user_name VARCHAR(30) NOT NULL,
     13    user_surname VARCHAR(30) NOT NULL,
     14    password VARCHAR(100) NOT NULL,
     15    role ENUM('student', 'teacher') NOT NULL
     16);
     17
     18
     19CREATE TABLE LabEquipment (
     20    equipment_id SERIAL PRIMARY KEY,
     21    equipment_name VARCHAR(50) NOT NULL UNIQUE,
     22    type VARCHAR(50),
     23    description TEXT,
     24    safety_info TEXT
     25);
     26
     27
     28CREATE TABLE Elements (
     29    element_id SERIAL PRIMARY KEY,
     30    symbol VARCHAR(2) NOT NULL UNIQUE,
     31    element_name VARCHAR(50) NOT NULL,
     32    atomic_number INT NOT NULL,
     33    atomic_weight FLOAT NOT NULL,
     34    melting_point FLOAT,
     35    boiling_point FLOAT,
     36    hazard_type VARCHAR(50),
     37    description_element TEXT
     38);
     39
     40
     41CREATE TABLE Reaction (
     42    reaction_id SERIAL PRIMARY KEY,
     43    element1_id INT NOT NULL REFERENCES Elements(element_id) ON DELETE CASCADE,
     44    element2_id INT NOT NULL REFERENCES Elements(element_id) ON DELETE CASCADE,
     45    product VARCHAR(50),
     46    conditions TEXT
     47);
     48
     49-- Создај табела за експерименти
     50CREATE TABLE Experiment (
     51    experiment_id SERIAL PRIMARY KEY,
     52    user_id INT NOT NULL REFERENCES USER (user_id) ON DELETE CASCADE,
     53    reaction_id INT NOT NULL REFERENCES Reaction(reaction_id) ON DELETE CASCADE,
     54    result TEXT,
     55    time_stamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
     56    safety_warning TEXT
     57);
     58
     59-- Создај поврзувачка табела за експерименти и лабораториска опрема
     60CREATE TABLE ExperimentLabEquipment (
     61    experiment_id INT NOT NULL REFERENCES Experiment(experiment_id) ON DELETE CASCADE,
     62    equipment_id INT NOT NULL REFERENCES LabEquipment(equipment_id) ON DELETE CASCADE,
     63
     64    PRIMARY KEY (experiment_id, equipment_id)
     65);
     66}}}