asked on
I believe it is wrong to rely on the SQL Database backend to populate multiple tables with data inserted into a single table and in my opinion (and hopefully many others) your UI / APP should INSERT/DELETE/UPDATE all necessary tables with the data as it should be stored in the database and not to rely on hidden SQL objects to do that for you.Sorry but I can't agree with you. Business model should always kept in the databases and a trigger isn't an hidden SQL object. It's more easy to change a trigger or stored procedure than an application code. Also, let the servers do the heaviest work and not the clients.
ASKER
ASKER
ASKER
CREATE TRIGGER INSERTTABLEPORTAL ON outlookreport.dbo.MFUSERS
AFTER INSERT
AS
BEGIN
-- stop the recursive trigger from firing more than once ... comment it out if you have bulk insert
IF ((SELECT TRIGGER_NESTLEVEL()) > 1 )
BEGIN
RETURN
END
IF EXISTS (SELECT xrefid FROM outlookreport.dbo.requestdoc)
INSERT INTO outlookreport.dbo.requestdoc values(xrefid,'test','Y','N')
SELECT xrefid,requested,status,required
FROM outlookreport.dbo.requestdoc
END
GO
ASKER
ASKER
USE [outlookreport]
GO
/****** Object: Trigger [dbo].[XREFID] Script Date: 11/14/2014 09:26:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[XREFID]
ON [outlookreport].[dbo].[MFUSERS]
AFTER INSERT
AS
DECLARE @XREFID NVARCHAR(50)
SET @XREFID = (SELECT TOP 1 XREFID FROM OUTLOOKREPORT.DBO.MFUSERS)
BEGIN
IF ((SELECT TRIGGER_NESTLEVEL()) > 1 )
BEGIN
RETURN
END
IF NOT EXISTS(SELECT XREFID FROM OUTLOOKREPORT.DBO.REQUESTDOC)
INSERT INTO OUTLOOKREPORT.DBO.REQUESTDOC (XREFID)
SELECT XREFID FROM OUTLOOKREPORT.DBO.MFUSERS
END
ASKER
USE [outlookreport]
GO
/****** Object: Trigger [dbo].[XREFID] Script Date: 11/14/2014 09:26:21 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[XREFID]
ON [outlookreport].[dbo].[MFUSERS]
AFTER INSERT
AS
BEGIN
IF ((SELECT TRIGGER_NESTLEVEL()) > 1 )
BEGIN
RETURN
END
IF NOT EXISTS(SELECT XREFID FROM OUTLOOKREPORT.DBO.MFUSERS)
INSERT INTO OUTLOOKREPORT.DBO.REQUESTDOC (XREFID)
SELECT XREFID FROM OUTLOOKREPORT.DBO.MFUSERS
END
ASKER
ASKER
Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.
TRUSTED BY
If the DB's are in the same instance you just need to give the full reference to the objects (DB.Schema.Object):
Open in new window
If there's no transformations or any other operations than simple inserts you can use a transactional replication instead of the triggers.