Link to home
Start Free TrialLog in
Avatar of Azurden
Azurden

asked on

MS SQL Trigger

Hey All!

Ok, new to MS SQL triggers...  SO, I need to try and do the following...

1: 2 tables SYS_USER, SERV_REQUEST, and SERV_NOTE
2: When a user is deleted from SYS_USER I need all refrences in SERV_REQUEST, and SERV_NOTE to be deleted as well.
3: I want the trigger to be on the SYS_USER table.

Here is the SQL for the tables and the joins...

SELECT
  user1229049.SYS_USER.ID_USER,
  user1229049.SYS_USER.ID_DISTRICT,
  user1229049.SYS_USER.ID_BUILDING,
  user1229049.SYS_USER.[USER_NAME],
  user1229049.SYS_USER.USER_PASSWORD,
  user1229049.SYS_USER.FIRST_NAME,
  user1229049.SYS_USER.LAST_NAME,
  user1229049.SYS_USER.EMAIL,
  user1229049.SYS_USER.RIGHTS,
  user1229049.SERV_REQUEST.ID_REQUEST,
  user1229049.SERV_REQUEST.ID_DISTRICT,
  user1229049.SERV_REQUEST.ID_BUILDING,
  user1229049.SERV_REQUEST.ID_ADMIN,
  user1229049.SERV_REQUEST.ID_TECHNICIAN,
  user1229049.SERV_REQUEST.ID_USER,
  user1229049.SERV_REQUEST.ID_PRIORITY,
  user1229049.SERV_REQUEST.ID_SUB_PRIORITY,
  user1229049.SERV_REQUEST.ID_ROOM,
  user1229049.SERV_REQUEST.ID_SERVICE_TYPE,
  user1229049.SERV_REQUEST.ID_SUB_SERVICE_TYPE,
  user1229049.SERV_REQUEST.ID_START_STATUS,
  user1229049.SERV_REQUEST.ID_SERVICE_STATUS,
  user1229049.SERV_REQUEST.ID_MODIFIED_LAST_BY,
  user1229049.SERV_REQUEST.INVENTORY_TAG,
  user1229049.SERV_REQUEST.REQUEST_POSTED_DATE,
  user1229049.SERV_REQUEST.REQUEST_REQUESTED_DATE,
  user1229049.SERV_REQUEST.REQUEST_OPEN_DATE,
  user1229049.SERV_REQUEST.REQUEST_MODIFIED_DATE,
  user1229049.SERV_REQUEST.REQUEST_CLOSED_DATE,
  user1229049.SERV_REQUEST.REQUEST_SERVICE_TIME_TOTAL,
  user1229049.SERV_REQUEST.ISSUE_DESCRIPTION,
  user1229049.SERV_NOTE.ID_NOTE,
  user1229049.SERV_NOTE.ID_SERV_REQUEST,
  user1229049.SERV_NOTE.ID_USER_TYPE,
  user1229049.SERV_NOTE.POSTED_DATE,
  user1229049.SERV_NOTE.NOTE
FROM
  user1229049.SYS_USER
  INNER JOIN user1229049.SERV_REQUEST ON (user1229049.SYS_USER.ID_USER = user1229049.SERV_REQUEST.ID_USER)
  INNER JOIN user1229049.SERV_NOTE ON (user1229049.SERV_REQUEST.ID_REQUEST = user1229049.SERV_NOTE.ID_SERV_REQUEST)

Here is the start of the trigger...

CREATE TRIGGER [SYS_USER (user1229049)].[SYS_USER_trd] ON [SYS_USER (user1229049)].[]
FOR DELETE
AS
BEGIN
  /* Trigger body */
END
GO

Any help would be great!

Az
ASKER CERTIFIED SOLUTION
Avatar of Otana
Otana

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial