eliteel5
Member
- Messages
- 63
- Reaction score
- 1
- Points
- 8
HI all , hope all well
Ive hit an issue this morning regarding db design Time UK 00:20hrs , Yep I do work some very long hours Strange as that may seem not to mention study and researching
Working on my local server I can create a relation database as you would normally comprising 3 tables , master table with two child tables with one to one relationship and one to many
How ever for some reason after setting up a procedure which should make this all easy , then on opening designer for the layout and plan of this using phpmyadmin on x10 then I have these issues below
1: Unable to see any relations btw tables
2: Unable to create relations btw tables
As such Im uploading code which for you to inspect hoping that some one can explain why that might be
I am also attaching image created from personal webserver running phpmyadmin using mariadb
Please see attached so that others can see the relationship diagram created as per code below
Ive hit an issue this morning regarding db design Time UK 00:20hrs , Yep I do work some very long hours Strange as that may seem not to mention study and researching
Working on my local server I can create a relation database as you would normally comprising 3 tables , master table with two child tables with one to one relationship and one to many
How ever for some reason after setting up a procedure which should make this all easy , then on opening designer for the layout and plan of this using phpmyadmin on x10 then I have these issues below
1: Unable to see any relations btw tables
2: Unable to create relations btw tables
As such Im uploading code which for you to inspect hoping that some one can explain why that might be
I am also attaching image created from personal webserver running phpmyadmin using mariadb
Please see attached so that others can see the relationship diagram created as per code below
SQL:
DELIMITER $$
-- These tables are to be added to the eliteel5_PowerReadingsDB
CREATE PROCEDURE CreateOfficeAndPowerTables()
BEGIN
-- Create Offices table (Parent)
IF NOT EXISTS (
SELECT * FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'Offices'
) THEN
CREATE TABLE Offices (
Office_ID VARCHAR(10) PRIMARY KEY ,
Salutation ENUM('MR', 'MRS', 'MISS') NOT NULL,
Name VARCHAR(10) NOT NULL,
Surname VARCHAR(20) NOT NULL,
Site_Name VARCHAR(20),
Office_Number VARCHAR(10),
Street VARCHAR(20),
Town VARCHAR(20),
County VARCHAR(20),
Postcode VARCHAR(20),
Email VARCHAR(50),
Date_Registered DATE ,
Contact_Number VARCHAR(20),
Notes TEXT,
Status ENUM('Active', 'Inactive') DEFAULT 'Active'
);
END IF;
-- Create PowerReadings table (Child)
IF NOT EXISTS (
SELECT * FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'PowerReadings'
) THEN
CREATE TABLE PowerReadings (
Reading_ID INT PRIMARY KEY AUTO_INCREMENT,
Office_ID VARCHAR(10) NOT NULL,
Date_Of_Reading DATE,
Time_Of_Reading TIME,
Network_Baud_Rate INT,
Total_system_power_demand DECIMAL(10,2),
Maximum_total_system_power_demand DECIMAL(10,2),
Current_system_positive_power_demand DECIMAL(10,2),
Maximum_system_positive_power_demand DECIMAL(10,2),
Current_system_reverse_power_demand DECIMAL(10,2),
Maximum_system_reverse_power_demand DECIMAL(10,2),
Current_demand DECIMAL(10,2),
Voltage DECIMAL(10,2),
Current DECIMAL(10,2),
Active_Power DECIMAL(10,2),
Apparent_Power DECIMAL(10,2),
Reactive_Power DECIMAL(10,2),
Power_Factor DECIMAL(5,2),
Phase_Angle DECIMAL(5,2),
Frequency DECIMAL(6,3),
Import_Active_Energy DECIMAL(12,2),
Export_Active_Energy DECIMAL(12,2),
Import_Reactive_Energy DECIMAL(12,2),
Maximum_current_Demand DECIMAL(10,2),
Export_Reactive_Energy DECIMAL(12,2),
Total_Active_Energy DECIMAL(12,2),
Total_Reactive_Energy DECIMAL(12,2),
FOREIGN KEY (Office_ID) REFERENCES Offices(Office_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
END IF;
-- Create PiDevices table with one-to-one Office_ID link
IF NOT EXISTS (
SELECT * FROM information_schema.TABLES
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'PiDevices'
) THEN
CREATE TABLE PiDevices (
Pi_ID INT PRIMARY KEY AUTO_INCREMENT,
Office_ID VARCHAR(10) UNIQUE,
CPU_Number VARCHAR(64),
Machine_ID VARCHAR(64),
Boot_ID VARCHAR(64),
Operating_System VARCHAR(100),
MAC_Address VARCHAR(20),
IP_Address VARCHAR(45),
Date_Installed DATE ,
Date_Changed DATE ,
Licensed ENUM('Yes', 'No') DEFAULT 'No',
FOREIGN KEY (Office_ID) REFERENCES Offices(Office_ID)
ON DELETE CASCADE
ON UPDATE CASCADE
);
END IF;
END $$
DELIMITER ;
Attachments
Last edited: