 
 ALTER TABLE AlarmLog ADD CONSTRAINT FK_AlarmLog_Alarm_NewState FOREIGN KEY(NewState) REFERENCES Alarm (ID) ON DELETE CASCADE ON UPDATE CASCADE;
 
-ALTER TABLE CustomOutputAdapter ADD CONSTRAINT FK_CustomOutputAdapter_Node FOREIGN KEY(NodeID) REFERENCES node (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE ApplicationRoleSecurityGroup ADD CONSTRAINT FK_applicationrolesecuritygroup_applicationrole FOREIGN KEY (ApplicationRoleID) REFERENCES applicationrole (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE ApplicationRoleSecurityGroup ADD CONSTRAINT FK_applicationrolesecuritygroup_securitygroup FOREIGN KEY (SecurityGroupID) REFERENCES securitygroup (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE UserAccount ADD CONSTRAINT FK_useraccount FOREIGN KEY (DefaultNodeID) REFERENCES node (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE ApplicationRole ADD CONSTRAINT FK_applicationrole FOREIGN KEY (NodeID) REFERENCES node (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE ApplicationRoleUserAccount ADD CONSTRAINT FK_applicationroleuseraccount_useraccount FOREIGN KEY (UserAccountID) REFERENCES useraccount (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE ApplicationRoleUserAccount ADD CONSTRAINT FK_applicationroleuseraccount_applicationrole FOREIGN KEY (ApplicationRoleID) REFERENCES applicationrole (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE SecurityGroupUserAccount ADD CONSTRAINT FK_securitygroupuseraccount_useraccount FOREIGN KEY (UserAccountID) REFERENCES useraccount (ID) ON DELETE CASCADE ON UPDATE CASCADE;
-
-ALTER TABLE SecurityGroupUserAccount ADD CONSTRAINT FK_securitygroupuseraccount_securitygroup FOREIGN KEY (SecurityGroupID) REFERENCES securitygroup (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+ALTER TABLE CustomOutputAdapter ADD CONSTRAINT FK_CustomOutputAdapter_Node FOREIGN KEY(NodeID) REFERENCES Node (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE ApplicationRoleSecurityGroup ADD CONSTRAINT FK_ApplicationRoleSecurityGroup_ApplicationRole FOREIGN KEY (ApplicationRoleID) REFERENCES ApplicationRole (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE ApplicationRoleSecurityGroup ADD CONSTRAINT FK_ApplicationRoleSecurityGroup_SecurityGroup FOREIGN KEY (SecurityGroupID) REFERENCES SecurityGroup (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE UserAccount ADD CONSTRAINT FK_UserAccount FOREIGN KEY (DefaultNodeID) REFERENCES Node (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE ApplicationRole ADD CONSTRAINT FK_ApplicationRole FOREIGN KEY (NodeID) REFERENCES Node (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE ApplicationRoleUserAccount ADD CONSTRAINT FK_ApplicationRoleUserAccount_UserAccount FOREIGN KEY (UserAccountID) REFERENCES UserAccount (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE ApplicationRoleUserAccount ADD CONSTRAINT FK_ApplicationRoleUserAccount_ApplicationRole FOREIGN KEY (ApplicationRoleID) REFERENCES ApplicationRole (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE SecurityGroupUserAccount ADD CONSTRAINT FK_SecurityGroupUserAccount_UserAccount FOREIGN KEY (UserAccountID) REFERENCES UserAccount (ID) ON DELETE CASCADE ON UPDATE CASCADE;
+
+ALTER TABLE SecurityGroupUserAccount ADD CONSTRAINT FK_SecurityGroupUserAccount_SecurityGroup FOREIGN KEY (SecurityGroupID) REFERENCES SecurityGroup (ID) ON DELETE CASCADE ON UPDATE CASCADE;
 
 CREATE VIEW NodeInfo
 AS


ALTER TABLE Node ADD CONSTRAINT FK_Node_Company FOREIGN KEY(CompanyID) REFERENCES Company (ID);

ALTER TABLE DataOperation ADD CONSTRAINT FK_DataOperation_Node FOREIGN KEY(NodeID) REFERENCES node (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE OtherDevice ADD CONSTRAINT FK_OtherDevice_Company FOREIGN KEY(CompanyID) REFERENCES Company (ID);



ALTER TABLE PowerCalculation ADD CONSTRAINT FK_PowerCalculation_Measurement7 FOREIGN KEY(VoltageMagSignalID) REFERENCES Measurement (SignalID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE Alarm ADD CONSTRAINT FK_Alarm_Node FOREIGN KEY(NodeID) REFERENCES Node (ID) ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE Alarm ADD CONSTRAINT FK_Alarm_Measurement_SignalID FOREIGN KEY(SignalID) REFERENCES Measurement (SignalID) ON DELETE CASCADE ON UPDATE CASCADE;

