Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sql openPDC specific sql scripts.
- Loading branch information
Billy Ernest
committed
Jan 12, 2018
1 parent
783dde5
commit 9eca152
Showing
7 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-- ******************************************************************************************* | ||
-- IMPORTANT NOTE: When making updates to this schema, please increment the version number! | ||
-- ******************************************************************************************* | ||
CREATE VIEW LocalSchemaVersion AS | ||
SELECT 1 AS VersionNumber; | ||
|
||
CREATE TABLE DataAvailability( | ||
ID int AUTO_INCREMENT NOT NULL, | ||
GoodAvailableData float NOT NULL, | ||
BadAvailableData float NOT NULL, | ||
TotalAvailableData float NOT NULL, | ||
PRIMARY KEY(ID) | ||
); | ||
|
||
|
||
CREATE TABLE AlarmDevice( | ||
ID int AUTO_INCREMENT NOT NULL, | ||
DeviceID int NULL, | ||
StateID int NULL, | ||
TimeStamp datetime NULL, | ||
DisplayData varchar(10) NULL, | ||
PRIMARY KEY(ID), | ||
FOREIGN KEY (DeviceID) REFERENCES Device(ID), | ||
FOREIGN KEY (StateID) REFERENCES AlarmState(ID) | ||
); | ||
|
||
CREATE TABLE AlarmState( | ||
ID int AUTO_INCREMENT NOT NULL, | ||
State varchar(50) NULL, | ||
Color varchar(50) NULL, | ||
PRIMARY KEY(ID) | ||
); | ||
|
||
INSERT INTO AlarmState (State, Color) VALUES ('Good', 'green'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Alarm', 'red'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Not Available', 'orange') | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Data', 'blue'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Time', 'purple'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Out of Service', 'grey'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
-- ******************************************************************************************* | ||
-- IMPORTANT NOTE: When making updates to this schema, please increment the version number! | ||
-- ******************************************************************************************* | ||
CREATE VIEW LocalSchemaVersion AS | ||
SELECT 1 AS VersionNumber | ||
FROM dual; | ||
|
||
|
||
CREATE TABLE DataAvailability( | ||
ID NUMBER NOT NULL, | ||
GoodAvailableData NUMBER NOT NULL, | ||
BadAvailableData NUMBER NOT NULL, | ||
TotalAvailableData NUMBER NOT NULL, | ||
); | ||
ALTER TABLE DataAvailability ADD CONSTRAINT PK_DataAvailability PRIMARY KEY (ID); | ||
|
||
CREATE SEQUENCE SEQ_DataAvailability START WITH 1 INCREMENT BY 1; | ||
|
||
CREATE TRIGGER AI_DataAvailability BEFORE INSERT ON DataAvailability | ||
FOR EACH ROW BEGIN SELECT SEQ_DataAvailability.nextval INTO :NEW.ID FROM dual; | ||
END; | ||
|
||
CREATE TABLE AlarmDevice( | ||
ID NUMBER IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
DeviceID NUMBER NULL, | ||
StateID NUMBER NULL, | ||
TimeStamp datetime NULL, | ||
DisplayData varchar(10) NULL | ||
); | ||
|
||
ALTER TABLE AlarmDevice ADD CONSTRAINT PK_AlarmDevice PRIMARY KEY (ID); | ||
ALTER TABLE AlarmDevice ADD CONSTRAINT FK_AlarmDevice_Device FOREIGN KEY(DeviceID) REFERENCES Device(ID) ON DELETE CASCADE; | ||
ALTER TABLE AlarmDevice ADD CONSTRAINT FK_AlarmDevice_State FOREIGN KEY(StateID) REFERENCES AlarmState(ID) ON DELETE CASCADE; | ||
|
||
CREATE SEQUENCE SEQ_AlarmDevice START WITH 1 INCREMENT BY 1; | ||
|
||
CREATE TRIGGER AI_AlarmDevice BEFORE INSERT ON AlarmDevice | ||
FOR EACH ROW BEGIN SELECT SEQ_AlarmDevice.nextval INTO :NEW.ID FROM dual; | ||
END; | ||
|
||
CREATE TABLE AlarmState( | ||
ID NUMBER NOT NULL, | ||
State varchar(50) NULL, | ||
Color varchar(50) NULL, | ||
); | ||
|
||
ALTER TABLE AlarmState ADD CONSTRAINT PK_AlarmState PRIMARY KEY (ID); | ||
|
||
CREATE SEQUENCE SEQ_AlarmState START WITH 1 INCREMENT BY 1; | ||
|
||
CREATE TRIGGER AI_AlarmState BEFORE INSERT ON AlarmState | ||
FOR EACH ROW BEGIN SELECT SEQ_AlarmState.nextval INTO :NEW.ID FROM dual; | ||
END; | ||
|
||
INSERT INTO AlarmState (State, Color) VALUES ('Good', 'green'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Alarm', 'red'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Not Available', 'orange'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Data', 'blue'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Time', 'purple'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Out of Service', 'grey'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
-- ******************************************************************************************* | ||
-- IMPORTANT NOTE: When making updates to this schema, please increment the version number! | ||
-- ******************************************************************************************* | ||
CREATE VIEW LocalSchemaVersion AS | ||
SELECT 1 AS VersionNumber; | ||
|
||
|
||
CREATE TABLE DataAvailability( | ||
ID SERIAL NOT NULL PRIMARY KEY, | ||
GoodAvailableData DOUBLE PRECISION NOT NULL, | ||
BadAvailableData DOUBLE PRECISION NOT NULL, | ||
TotalAvailableData DOUBLE PRECISION NOT NULL, | ||
); | ||
|
||
CREATE TABLE AlarmDevice( | ||
ID SERIAL NOT NULL PRIMARY KEY, | ||
DeviceID INTEGER NULL FOREIGN KEY REFERENCES Device(ID), | ||
StateID INTEGER NULL FOREIGN KEY REFERENCES AlarmState(ID), | ||
TimeStamp TIMESTAMP NULL, | ||
DisplayData varchar(10) NULL, | ||
CONSTRAINT FK_AlarmDevice_Device FOREIGN KEY(DeviceID) REFERENCES Device (ID) ON DELETE CASCADE, | ||
CONSTRAINT FK_AlarmDevice_AlarmState FOREIGN KEY(StateID) REFERENCES AlarmState (ID) ON DELETE CASCADE | ||
|
||
); | ||
|
||
CREATE TABLE AlarmState( | ||
ID SERIAL NOT NULL PRIMARY KEY, | ||
State varchar(50) NULL, | ||
Color varchar(50) NULL, | ||
); | ||
|
||
INSERT INTO AlarmState (State, Color) VALUES ('Good', 'green'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Alarm', 'red'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Not Available', 'orange') | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Data', 'blue'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Time', 'purple'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Out of Service', 'grey'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
-- ******************************************************************************************* | ||
-- IMPORTANT NOTE: When making updates to this schema, please increment the version number! | ||
-- ******************************************************************************************* | ||
CREATE VIEW [dbo].[LocalSchemaVersion] AS | ||
SELECT 1 AS VersionNumber | ||
GO | ||
|
||
CREATE TABLE DataAvailability( | ||
ID int IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
GoodAvailableData float NOT NULL, | ||
BadAvailableData float NOT NULL, | ||
TotalAvailableData float NOT NULL, | ||
) | ||
|
||
GO | ||
|
||
|
||
CREATE TABLE AlarmDevice( | ||
ID int IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
DeviceID int NULL FOREIGN KEY REFERENCES Device(ID), | ||
StateID int NULL FOREIGN KEY REFERENCES AlarmState(ID), | ||
TimeStamp datetime NULL, | ||
DisplayData varchar(10) NULL | ||
) | ||
GO | ||
|
||
CREATE TABLE AlarmState( | ||
ID int IDENTITY(1,1) NOT NULL PRIMARY KEY, | ||
State varchar(50) NULL, | ||
Color varchar(50) NULL, | ||
) | ||
|
||
GO | ||
|
||
INSERT AlarmState (State, Color) VALUES ('Good', 'green') | ||
GO | ||
INSERT AlarmState (State, Color) VALUES ('Alarm', 'red') | ||
GO | ||
INSERT AlarmState (State, Color) VALUES ('Not Available', 'orange') | ||
GO | ||
INSERT AlarmState (State, Color) VALUES ('Bad Data', 'blue') | ||
GO | ||
INSERT AlarmState (State, Color) VALUES ('Bad Time', 'purple') | ||
GO | ||
INSERT AlarmState (State, Color) VALUES ('Out of Service', 'grey') | ||
GO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
-- ******************************************************************************************* | ||
-- IMPORTANT NOTE: When making updates to this schema, please increment the version number! | ||
-- ******************************************************************************************* | ||
CREATE VIEW LocalSchemaVersion AS | ||
SELECT 1 AS VersionNumber; | ||
|
||
CREATE TABLE DataAvailability( | ||
ID int PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
GoodAvailableData DOUBLE NOT NULL, | ||
BadAvailableData DOUBLE NOT NULL, | ||
TotalAvailableData DOUBLE NOT NULL | ||
); | ||
|
||
|
||
CREATE TABLE AlarmDevice( | ||
ID int PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
DeviceID int NULL, | ||
StateID int NULL, | ||
TimeStamp datetime NULL, | ||
DisplayData varchar(10) NULL, | ||
CONSTRAINT FK_AlarmDevice_Device FOREIGN KEY(DeviceID) REFERENCES Device (ID) ON DELETE CASCADE ON UPDATE CASCADE, | ||
CONSTRAINT FK_AlarmDevice_AlarmState FOREIGN KEY(StateID) REFERENCES AlarmState (ID) ON DELETE CASCADE ON UPDATE CASCADE | ||
); | ||
|
||
CREATE TABLE AlarmState( | ||
ID int PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
State varchar(50) NULL, | ||
Color varchar(50) NULL, | ||
); | ||
|
||
INSERT INTO AlarmState (State, Color) VALUES ('Good', 'green'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Alarm', 'red'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Not Available', 'orange') | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Data', 'blue'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Bad Time', 'purple'); | ||
INSERT INTO AlarmState (State, Color) VALUES ('Out of Service', 'grey'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters