
  ALTER TABLE Links ADD INDEX(LocalBase);
  ALTER TABLE Links ADD FOREIGN KEY (LocalBase) REFERENCES Tickets(id);
  ALTER TABLE Links ADD INDEX(LocalTarget);
  ALTER TABLE Links ADD FOREIGN KEY (LocalTarget) REFERENCES Tickets(id);
  ALTER TABLE Tickets ADD INDEX(Queue);
  ALTER TABLE Tickets ADD FOREIGN KEY (Queue) REFERENCES Queues(id);
  ALTER TABLE Tickets ADD INDEX(EffectiveId);
  ALTER TABLE Tickets ADD FOREIGN KEY (EffectiveId) REFERENCES Tickets(id);
  ALTER TABLE Tickets ADD INDEX(Owner);
  ALTER TABLE Tickets ADD FOREIGN KEY (Owner) REFERENCES Principals(id);
  ALTER TABLE Tickets ADD INDEX(Creator);
  ALTER TABLE Tickets ADD INDEX(LastUpdatedBy);
  ALTER TABLE Tickets ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE Tickets ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
  ALTER TABLE Transactions ADD INDEX(Creator);
  ALTER TABLE Transactions ADD INDEX (Ticket) ;
  ALTER TABLE Transactions ADD INDEX (EffectiveTicket) ;
  ALTER TABLE Transactions ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE Transactions ADD FOREIGN KEY (Ticket) REFERENCES Tickets(id);
  ALTER TABLE Transactions ADD FOREIGN KEY (EffectiveTicket) REFERENCES Tickets(id);
  ALTER TABLE Attachments ADD INDEX (TransactionId) ;
  ALTER TABLE Attachments ADD INDEX (Parent) ;
  ALTER TABLE Attachments ADD FOREIGN KEY (TransactionId) REFERENCES Transactions(id);
  ALTER TABLE Attachments ADD FOREIGN KEY (Parent) REFERENCES Attachments(id);
  ALTER TABLE Scrips ADD INDEX (ScripCondition) ;
  ALTER TABLE Scrips ADD INDEX (ScripAction) ;
  ALTER TABLE Scrips ADD INDEX (Template) ;
  ALTER TABLE Scrips ADD INDEX (Queue) ;
  ALTER TABLE Scrips ADD INDEX (Creator) ;
  ALTER TABLE Scrips ADD INDEX (LastUpdatedBy) ;
  ALTER TABLE Scrips ADD FOREIGN KEY (ScripCondition) REFERENCES ScripConditions(id);
  ALTER TABLE Scrips ADD FOREIGN KEY (ScripAction) REFERENCES ScripActions(id);
  ALTER TABLE Scrips ADD FOREIGN KEY (Template) REFERENCES Templates(id);
  ALTER TABLE Scrips ADD FOREIGN KEY (Queue) REFERENCES Queues(id);
  ALTER TABLE Scrips ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE Scrips ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
  ALTER TABLE ACL ADD INDEX (PrincipalId) ;
  ALTER TABLE ACL ADD INDEX (DelegatedBy) ;
  ALTER TABLE ACL ADD INDEX (DelegatedFrom) ;
  ALTER TABLE ACL ADD FOREIGN KEY (PrincipalId) REFERENCES Principals(id);
  ALTER TABLE ACL ADD FOREIGN KEY (DelegatedBy) REFERENCES Principals(id);
  ALTER TABLE ACL ADD FOREIGN KEY (DelegatedFrom) REFERENCES ACL(id);
  ALTER TABLE GroupMembers ADD INDEX (MemberId); 
  ALTER TABLE GroupMembers ADD INDEX (GroupId); 
  ALTER TABLE GroupMembers ADD FOREIGN KEY (GroupId) REFERENCES Groups(id);
  ALTER TABLE GroupMembers ADD FOREIGN KEY (MemberId) REFERENCES Principals(id);
  ALTER TABLE CachedGroupMembers ADD INDEX (ImmediateParentId) ;
  ALTER TABLE CachedGroupMembers ADD INDEX (GroupId) ;
  ALTER TABLE CachedGroupMembers ADD INDEX (MemberId) ;
  ALTER TABLE CachedGroupMembers ADD INDEX (Via) ;
  ALTER TABLE CachedGroupMembers ADD FOREIGN KEY (ImmediateParentId) REFERENCES Principals(id);
  ALTER TABLE CachedGroupMembers ADD FOREIGN KEY (GroupId) REFERENCES Principals(id);
  ALTER TABLE CachedGroupMembers ADD FOREIGN KEY (MemberId) REFERENCES Principals(id);
  ALTER TABLE CachedGroupMembers ADD FOREIGN KEY (Via) REFERENCES CachedGroupMembers(id);
  ALTER TABLE ScripActions ADD INDEX(Creator);
  ALTER TABLE ScripActions ADD INDEX(LastUpdatedBy);
  ALTER TABLE ScripActions ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE ScripActions ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
  ALTER TABLE Templates ADD INDEX(Queue);
  ALTER TABLE Templates ADD INDEX(Creator);
  ALTER TABLE Templates ADD INDEX(LastUpdatedBy);
  ALTER TABLE Templates ADD FOREIGN KEY (Queue) REFERENCES Queues(id);
  ALTER TABLE Templates ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE Templates ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
  ALTER TABLE CustomFields ADD INDEX(Queue);
  ALTER TABLE CustomFields ADD INDEX(Creator);
  ALTER TABLE CustomFields ADD INDEX(LastUpdatedBy);
  ALTER TABLE CustomFields ADD FOREIGN KEY (Queue) REFERENCES Queues(id);
  ALTER TABLE CustomFields ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE CustomFields ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
  ALTER TABLE TicketCustomFieldValues ADD INDEX(Ticket);
  ALTER TABLE TicketCustomFieldValues ADD INDEX(CustomField);
  ALTER TABLE TicketCustomFieldValues ADD INDEX(Creator);
  ALTER TABLE TicketCustomFieldValues ADD INDEX(LastUpdatedBy);
  ALTER TABLE TicketCustomFieldValues ADD FOREIGN KEY (Ticket) REFERENCES Tickets(id);
  ALTER TABLE TicketCustomFieldValues ADD FOREIGN KEY (CustomField) REFERENCES CustomFields(id);
  ALTER TABLE TicketCustomFieldValues ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE TicketCustomFieldValues ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
  ALTER TABLE CustomFieldValues ADD INDEX(CustomField);
  ALTER TABLE CustomFieldValues ADD INDEX(Creator);
  ALTER TABLE CustomFieldValues ADD INDEX(LastUpdatedBy);
  ALTER TABLE CustomFieldValues ADD FOREIGN KEY (CustomField) REFERENCES CustomFields(id);
  ALTER TABLE CustomFieldValues ADD FOREIGN KEY (Creator) REFERENCES Users(id);
  ALTER TABLE CustomFieldValues ADD FOREIGN KEY (LastUpdatedBy) REFERENCES Users(id);
