MS SQL-server trigger
Hi,
I wonder if there is anyone who know if there is any method as listen on a table in a ms sql-server. I want my program to run if a new row appear in the database.
/Rikard
Why would you need to do that? Put all theprocessing
into the trigger, that's where it belongs.Possibly a bad assumption on my part, but since this
is op posted in a java forum and said:
"I want my program to run if a new row appear in the
database"
I assumed he has a program and that it is probably
made with Java.
I think nasch_ meant basically that perhaps the business logic that this 'app' does, really belongs in the database trigger.
Similar Messages
-
Can I call a Java program from a SQL Server Trigger?
Hello,
I want to encrypt some data in a database column in SQL Server. Today I am using java code to encrypt the value and store it in the database using JDBC.
Now I want to use a VB client to store the encrypted value in the SQL Server DB. Since the encryption is handled by a java class, can I write a trigger in SQL Server that while inserting the raw data, calls the java class for encrypting the value and then inserts the encrypted value into the column?
In general, is it possible to call a java class from a SQL Server trigger?
Thanks
BipinHere are 3 examples of code for insert, update and delete:
CREATE TRIGGER [PLI_INSERT_TRIGGER] ON [dbo].[PLI]
FOR INSERT
AS
Declare @cmd sysname, @code sysname, @list sysname
Select @code = PLI_K_COD, @list = PLI_K_LISTINO from inserted
Set @cmd = 'java mirrorDb.Copy PLI INSERT ' + @code + ' ' + @list
EXEC master..xp_cmdshell @cmd
CREATE TRIGGER [PLI_UPDATE_TRIGGER] ON [dbo].[PLI]
FOR UPDATE
AS
Declare @cmd sysname, @code sysname, @list sysname
Select @code = PLI_K_COD, @list = PLI_K_LISTINO from inserted
Set @cmd = 'java mirrorDb.Copy PLI UPDATE ' + @code + ' ' + @list
EXEC master..xp_cmdshell @cmd
CREATE TRIGGER [PLI_DELETE_TRIGGER] ON [dbo].[PLI]
FOR DELETE
AS
Declare @cmd sysname, @code sysname, @list sysname
Select @code = PLI_K_COD, @list = PLI_K_LISTINO from deleted
Set @cmd = 'java mirrorDb.Copy PLI DELETE ' + @code + ' ' + @list
EXEC master..xp_cmdshell @cmd
you must go "sql server entreprise manager" right click on the table you want to add triggers and select: all activities, manage triggers.
You have 3 examples: for an insert, for an update and for a delete
ON [dbo].[PLI] specify the table on which you want to setup trigger.
FOR DELETE, INSERT, UPDATE specify the event.
The Declare statement create the variables in which I want to put some values to pass to the java program, for example which table, which event, which key fields.
the "Select @code = PLI_K_COD, @list = PLI_K_LISTINO from inserted" set the variables with the value of the columns of the table I am interested to read from my java program, for example the variable @code receive the value of the column pli_k_kod (is the key) of the table PLI.
The "Set @cmd = 'java mirrorDb.Copy PLI DELETE ' + @code + ' ' + @list " prepared the variable @cmd with the java command followed by the package.classname and parameters.
The EXEC launch the command to the operating system.
Daniele -
PowerShell and SQL Server Trigger
I had the following trigger written but apparently our IT department has not set up server/account or whatever needs to be done to use SQL Server's DB Mail.
ALTER TRIGGER [dbo].[Faxiles_Trigger]
ON [dbo].[DummyFQF]
AFTER INSERT
AS
BEGIN
DECLARE @tableHTML NVARCHAR(MAX) ;
SET @tableHTML =
N'<H1>Fax Error Report</H1>' +
N'<table border="1">' +
N'<tr><th>[FileID]</th>
<th>[FaxID]</th>
<th>[FilePath]</th></tr>' +
CAST ( (
SELECT
td=T1.[FileID],' ',
td=T1.[FaxID],' ',
td=T1.[FilePath],' '
FROM
FaxQueueFiles as T1
INNER JOIN
FaxQueue as T2
ON
T1.[FaxID] = T2.[FaxID]
WHERE
T2.[DateAdded] between Dateadd(hour,-1,GETDATE()) and Getdate()
AND
T1.[FilePath] NOT LIKE 'C:\%'
FOR XML PATH('tr'), TYPE
) AS NVARCHAR(MAX) ) +
N'</table>' ;
EXEC msdb.dbo.sp_send_dbmail
@recipients='[email protected]',
@subject = 'Fax Error Report',
@body = @tableHTML,
@body_format = 'HTML';
END
How can I instead make the trigger envoke/call a powershell script that can perform the same query and send an e-mail?
Apparently we do have e-mail functionality for our scripts, so that part I can just copy/paste from a pre-existing script. What I don't know how to do (since I am brand new to powershell scripting) is save the results of a query into a HTML-f0rmatted table
as the body of the e-mail like I did with SQL.
Thanks in advance for any assistance you can provide.
# Connect to the database.
$dbConnSites = New-Object System.Data.SqlClient.SqlConnection("Data Source=localhost;Initial Catalog=Main;Integrated Security=SSPI");
# Open database connection.
$dbConnSites.Open();
# Query String
$dbQry_BadTIFs = "
SELECT
T1.[FileID], T1.[FaxID], T1.[FilePath]
FROM
Main.FaxQueueFiles as T1
INNER JOIN
FaxQueue as T2
ON
T1.FaxID = T2.FaxID
WHERE
T2.[DateAdded] between DATEADD(hour,-1,GETDATE()) and GETDATE()
AND
T1.[FilePath] NOT LIKE 'C:\%'
# Create an SQL Command to execute the above query using the database connection object
$dbGetBadTIFs = New-Object System.Data.SqlClient.SqlCommand(dbQry_BadTIFs, $dbConnSites);
# Reader object to read the results of the executed SQL Command
$dbGetBadTIFsReader = $dbGetBadTIFs.ExecuteReader();
# Loop through the results of GetBadTIFs
while ($dbGetBadTFIsReader.Read())
# Close all the database connections
$dbConnSites.Close();
The above code is what I've come up with so far.... So within my while loop I presume the E-mail will some how be generated?
Should I declare a new string object and concatenate within the loop?
# Start the HTML Table for the e-mail
$str_EmailBody = "
<H1>Fax Error Report<H1>
<TABLE border=`"1`">
<TR>
<TH>[FileID]</TH>
<TH>[FaxID]</TH>
<TH>[FilePath]</TH>
</TR>
</TABLE>
# Loop through the results of GetBadTIFs
# to fill out the HTML Table
while ($dbRdr_GetBadTIFs.Read())
$str_EmailBody += "???";
# Finish the HTML Table for the e-mail
$str_EmailBody += "
</TR>
</TABLE>";
-Nothing to see. Move along.Hi Blacksaibot,
If you want to query the sql cmd and send eamil with the result, please refer this script, to save the result of the query, plrease try to create a sql datatable:
PowerShell Display Table In HTML Email
If I have any misunderstanding, please let me know.
Best Regards,
Anna -
Parse error in line 10, column 9. encountered INSERT.
here is the code :
CREATE TRIGGER delCategoria ON dbo.CATEGORIA
FOR DELETE
AS
declare @usuarioTMS varchar(50)
IF(UPPER(substring(APP_NAME(),1,4))='TMS\')
set @usuarioTMS=UPPER(substring(APP_NAME(),1,50))
Else
set @usuarioTMS=UPPER(substring(SYSTEM_USER,1,50))
INSERT INTO LOG
(responsable,
modulo,
tipo,
descripcion,
datos_modificados)
SELECT @usuarioTMS,
'Administracion',
'E',
'Eliminación en Categoria',
'Id CategorÃa: ' + convert(varchar,deleted.id_categoria) + ' - Nombre: ' + deleted.nombre
FROM delete
Colud you help me, i dont find any error in this code.I think the last line should be 'FROM deleted'. Also try the parser option Allow 'Reserved Words' in table names, in this case the parser is confused by the table name LOG (you could change it to myLOG and edit the result back to LOG in the oracle model if you prefer.)
I hope that gets you over that issue.
Regards,
Turloch
Oracle Migration Workbench Team -
Trigger to populate table in sql server database
Maybe this isn't the right board to post this in, but here goes:
We have an Oracle 9i database, with a table that get's populated with a new record every minute or so.
We need to take some values from the newly inserted record and populate a table in a sql server database instantly. The people requesting this have not said as much, but I am thinking deletes and updates would need to be the same.
How would it be best to do this? My first thought was a trigger on the oracle table that populates the sql server table via heterogeneous db link.
Any other ideas?
thanks in advance..
update- repost in heterogeneous forum
Edited by: user571263 on Mar 15, 2011 11:25 AMMaybe this isn't the right board to post this inI think you are right:
Heterogeneous Connectivity
Werner -
Sql server 2012 Logon trigger not working for certain logins
Hello. I created a login trigger to insert data for each login in a table, and it works for all logins except one that is format domain\login
and the login ends with the dollar sign(actual name is domain\CTXDEVDCSI1$).
I had been using varchar, but after reading other forum posts, I changed the varchar's to nvarchar's, but it still fails for that id.
The errors written to the sql server error log were the usual "login failed due to trigger execution".
I had granted insert on the rvvlogindata table in dsa to public, and only one id wasn't able to login after that.
Any suggestions would be much appreciated!
Here's the modified table ddl:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[rvvlogindata](
[sessionId] [int] NULL,
[LoginTime] [datetime] NULL,
[HostName] [nvarchar](50) NULL,
[ProgramName] [nvarchar](300) NULL,
[LoginName] [nvarchar](50) NULL,
[ClientHost] [nvarchar](50) NULL
) ON [PRIMARY]
GO
Here's the logon trigger code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create trigger [LOGIN_IP_RESTRICTION] on all server for logon
as
Begin
Declare @LogonTriggerData xml,
@EventTime datetime,
@LoginName nvarchar(50),
@ClientHost nvarchar(50),
@HostName nvarchar(50),
@AppName nvarchar(300)
Set @LogonTriggerData = eventdata()
set @EventTime = @LogonTriggerData.value('(/EVENT_INSTANCE/PostTime)[1]', 'datetime')
set @LoginName = @LogonTriggerData.value('(/EVENT_INSTANCE/LoginName)[1]', 'varchar(50)')
set @ClientHost = @LogonTriggerData.value('(/EVENT_INSTANCE/ClientHost)[1]', 'varchar(50)')
set @HostName = HOST_NAME()
set @AppName = APP_NAME()
insert into dsa.dbo.rvvlogindata
sessionId,
LoginTime,
HostName,
ProgramName,
LoginName,
ClientHost
select @@spid,
@EventTime,
convert(nvarchar(50),@HostName),
convert(nvarchar(300),@AppName),
convert(nvarchar(50),@LoginName),
convert(nvarchar(50),@ClientHost)
END
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
ENABLE TRIGGER [LOGIN_IP_RESTRICTION] ON ALL SERVER
GOErland, I wanted to add more info to my reply earlier today.
sp_who2 showed no blocking, activity monitor from my local PC SSMS showed no major waits or high i/o or cpu activity.
I was wondering if you have any suggestions on how to find out what was the cause of the 5+ minute wait for SSMS on the remote desktop to respond and fully come up.
I definitely can't put this in production with this hanging delay possibly occurring there.
I was connecting as read_user when it hung.
sp_who2 output at the time was:
1 BACKGROUND sa . . NULL LOG WRITER 54631 0 04/10
06:59:43
1 0
2 BACKGROUND sa . . NULL RECOVERY WRITER 8673 0 04/10 06:59:43
2 0
3 BACKGROUND sa . . NULL LAZY WRITER 300691 0 04/10
06:59:43
3 0
4 BACKGROUND sa . . NULL RESOURCE MONITOR 1207010 0 04/10 06:59:43
4 0
5 BACKGROUND sa . . NULL XE TIMER 38828 0 04/10
06:59:43
5 0
6 BACKGROUND sa . . NULL XE DISPATCHER 1404 0 04/10
06:59:43
6 0
7 BACKGROUND sa . . master SIGNAL HANDLER 0 0 04/10 06:59:43
7 0
8 BACKGROUND sa . . NULL LOCK MONITOR 179978 0 04/10
06:59:43
8 0
9 sleeping sa . . master TASK MANAGER 0 11 04/21
08:37:04
9 0
10 sleeping sa . . master TASK MANAGER 0 0 04/10
06:59:44
10 0
11 BACKGROUND sa . . master TRACE QUEUE TASK 546 0 04/10 06:59:44
11 0
12 BACKGROUND sa . . NULL SYSTEM_HEALTH_MO 4930 0 04/10 06:59:44
12 0
13 BACKGROUND sa . . NULL RECEIVE 422 0 04/10
06:59:45
13 0
14 BACKGROUND sa . . master CHECKPOINT 79137 31811 04/10
06:59:46
14 0
15 BACKGROUND sa . . master TASK MANAGER 1606 0 04/10
06:59:46
15 0
16 BACKGROUND sa . . NULL UNKNOWN TOKEN 0 0 04/10 06:59:46
16 0
17 sleeping sa . . master TASK MANAGER 0 74 04/21
08:37:04
17 0
18 sleeping sa . . master TASK MANAGER 0 0 04/21
08:18:49
18 0
19 sleeping sa . . master TASK MANAGER 0 0 04/21
08:30:29
19 0
20 sleeping sa . . master TASK MANAGER 0 1 04/21
08:37:14
20 0
21 sleeping sa . . master TASK MANAGER 0 7 04/21
08:30:59
21 0
22 sleeping sa . . master TASK MANAGER 16 4 04/21
08:37:44
22 0
23 sleeping sa . . master TASK MANAGER 0 15 04/21
08:39:24
23 0
25 BACKGROUND sa . . master BRKR EVENT HNDLR 0 95 04/10 06:59:48
25 0
30 BACKGROUND sa . . master BRKR TASK 0 0 04/10
06:59:48
30 0
31 BACKGROUND sa . . master BRKR TASK 16926 0 04/10
06:59:48
31 0
32 BACKGROUND sa . . master BRKR TASK 0 0 04/10
06:59:48
32 0
34 BACKGROUND sa . . master BRKR TASK 10701 0 04/10
06:59:48
34 0
51 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
03:16:56
51 0
52 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
52 0
53 sleeping NT AUTHORITY\SYSTEM SQLDEV2012 . msdb AWAITING COMMAND 0 0 04/10
06:59:58 SQLAgent - Email Logger 53 0
54 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:51 Citrix:Broker#1 54 0
55 sleeping edit_user ASDEV1 . dsa AWAITING
COMMAND 0 0 04/21 08:55:27 jTDS
55 0
56 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
56 0
57 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
57 0
58 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
58 0
59 sleeping NT AUTHORITY\SYSTEM SQLDEV2012 . msdb AWAITING COMMAND 124 242 04/10
06:59:59 SQLAgent - Generic Refresher 59 0
60 sleeping NT AUTHORITY\SYSTEM SQLDEV2012 . msdb AWAITING COMMAND 2790 1160 04/21
08:55:00 SQLAgent - Job invocation engine 60 0
61 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
61 0
62 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
62 0
63 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
63 0
64 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
64 0
65 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
65 0
66 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
03:16:56
66 0
67 sleeping reports_adm REPORTSDEVSI2 . JBOSS_Cluster_CRServer2011 AWAITING COMMAND 0 0 04/21
08:52:12 jTDS
67 0
68 sleeping edit_user DCMA10685 . dsa AWAITING COMMAND 0 0 04/21
08:56:47 jTDS
68 0
69 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:49 Citrix:Configuration 69 0
70 sleeping rvanveen DCMA8460 . master AWAITING COMMAND 1794 7120 04/21
08:51:37 Microsoft SQL Server Management Studio 70 0
71 sleeping xsp_user XSPDEVSI2 . xspv5 AWAITING COMMAND 0 0 04/21
08:58:52 .Net SqlClient Data Provider 71 0
72 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:56:01 Citrix:Monitor 72 0
73 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:30 Citrix:Monitor 73 0
74 sleeping rvanveen DCMA8460 . master AWAITING COMMAND 16 2 04/21
08:53:37 Microsoft SQL Server Management Studio - Query 74 0
75 sleeping rvanveen DCMA8460 . loginaudit AWAITING COMMAND 0 22 04/21
08:50:29 Microsoft SQL Server Management Studio - Query 75 0
76 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:05:07
76 0
77 sleeping adm_jbossportal ASDEV1 . jbossportal AWAITING
COMMAND 0 0 04/21 08:40:27 jTDS
77 0
78 sleeping rvanveen DCMA8460 . master AWAITING COMMAND 110 542 04/21
08:46:17 Microsoft SQL Server Management Studio - Query 78 0
79 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:05:56
79 0
80 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:54 Citrix:MachineCreation 80 0
81 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
08:08:29
81 0
82 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:02:13
82 0
83 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:02:15
83 0
84 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:44 Citrix:Monitor 84 0
85 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:11:05
85 0
86 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:53 Citrix:AdIdentity 86 0
87 sleeping DAIWA_USA\admsql SQLDEV2012 . master AWAITING COMMAND 15 2 04/21
08:56:20 Microsoft SQL Server Management Studio - Query 87 0
88 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:36 Citrix:SiteServices 88 0
89 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:42 Citrix:Host 89 0
90 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:47 Citrix:ConfigurationLogging 90 0
91 RUNNABLE rvanveen DCMA8460 . master SELECT INTO
15 51 04/21 08:58:46 Microsoft SQL Server Management Studio - Query 91 0
92 sleeping rvanveen DCMA8460 . master AWAITING COMMAND 63 30 04/21
08:52:34 Microsoft SQL Server Management Studio - Query 92 0
94 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:53 Citrix:DelegatedAdmin 94 0
95 sleeping DAIWA_USA\admsql SQLDEV2012 . loginaudit AWAITING COMMAND 173 27 04/21
08:56:10 Microsoft SQL Server Management Studio 95 0
96 sleeping xsp_user XSPDEVSI2 . xspv5 AWAITING COMMAND 0 0 04/21
08:58:33 .Net SqlClient Data Provider 96 0
97 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
08:10:07
97 0
98 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 31 38 04/21
08:00:31
98 0
99 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
08:10:12
99 0
100 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 282 04/21
08:10:14
100 0
101 sleeping DAIWA_USA\admsql SQLDEV2012 . master AWAITING COMMAND 0 8 04/21
08:56:50 Microsoft SQL Server Management Studio 101 0
102 sleeping DAIWA_USA\admsql SQLDEV2012 . master AWAITING COMMAND 31 0 04/21
08:54:57 Microsoft SQL Server Management Studio 102 0
103 sleeping read_user SQLDEV2012 . master AWAITING COMMAND 0 8 04/21
08:57:09 Microsoft SQL Server Management Studio 103 0
104 sleeping read_user SQLDEV2012 . dsa AWAITING COMMAND 0 0 04/21
08:57:09 Microsoft SQL Server Management Studio 104 0
105 sleeping rvanveen DCMA8460 . tempdb AWAITING COMMAND 8875 336 04/21
08:58:54 Microsoft SQL Server Management Studio 105 0
106 sleeping read_user SQLDEV2012 . master AWAITING COMMAND 16 0 04/21
08:57:39 Microsoft SQL Server Management Studio 106 0
107 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:47 Citrix:EnvTest 107 0
108 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 2200 8514 04/21
08:00:31
108 0
109 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:05:56
109 0
110 sleeping rvanveen DCMA8460 . master AWAITING COMMAND 0 0 04/21
08:58:48 Microsoft SQL Server Management Studio 110 0
113 sleeping Citrix_adm CTXDEVSI1 . XenApp6 AWAITING COMMAND 284 777 04/21
08:51:33 Citrix IMA 113 0
119 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:42 Citrix:ConfigurationLoggingData 119 0
120 sleeping AMERICAS\CTXDEVDCSI1$ CTXDEVDCSI1 . CitrixXDFarm1 AWAITING COMMAND 0 0 04/21
08:58:26 Citrix:Storefront 120 0
125 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/16
13:55:16
125 0
126 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 16 0 04/16
11:25:30
126 0
131 sleeping echouliak DCMA10685 . master AWAITING COMMAND 139 8 04/14
15:26:55 Microsoft SQL Server Management Studio 131 0
135 sleeping echouliak DCMA10685 . dsa AWAITING COMMAND 0 0 04/14
15:24:52 Microsoft SQL Server Management Studio - Query 135 0
136 sleeping echouliak DCMA10685 . dsa AWAITING COMMAND 0 0 04/14
15:00:17 Microsoft SQL Server Management Studio - Query 136 0
140 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:05:56
140 0
145 sleeping edit_user INFADEVFS2 . dsa AWAITING COMMAND 0 0 04/21
07:05:56
145 0 -
How to use update trigger in sql server 2008 with specific column
Hello friends currently my trigger updates on table update, and I need to change this to only fire when specific column changes.
/****** Object: Table [dbo].[User_Detail] ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[User_Detail](
[sno] [int] IDENTITY(1,1) NOT NULL,
[userid] [nvarchar](50) NULL,
[name] [nvarchar](max) NULL,
[jointype] [nvarchar](50) NULL,
[joinside] [nvarchar](50) NULL,
[lleg] [nvarchar](50) NULL,
[rleg] [nvarchar](50) NULL,
[ljoining] [int] NULL,
[rjoining] [int] NULL,
[pair] [int] NULL
) ON [PRIMARY]
GO
/****** Object: Table [dbo].[User_Detail] table data ******/
SET IDENTITY_INSERT [dbo].[User_Detail] ON
INSERT [dbo].[User_Detail] values (1, N'LDS', N'LDS Rajput', N'free', N'Left', N'jyoti123', N'SUNIL', 6, 4, 4)
INSERT [dbo].[User_Detail] VALUES (2, N'jyoti123', N'jyoti rajput', N'free', N'Left', N'mhesh123', N'priya123', 3, 2, 2)
SET IDENTITY_INSERT [dbo].[User_Detail] OFF
/****** Object: Table [dbo].[User_Detail] trigger ******/
CREATE TRIGGER triggAfterUpdate ON User_Detail
FOR UPDATE
AS
declare @userid nvarchar(50);
declare @pair varchar(100);
select @userid=i.userid from inserted i;
select @pair=i.pair from inserted i;
SET NOCOUNT ON
if update(pair)
begin
insert into Complete_Pairs(userid,pair)
values(@userid,1);
end
GO
/****** Object: Table [dbo].[Complete_Pairs] Script Date: 05/22/2014 21:20:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Complete_Pairs](
[Sno] [int] IDENTITY(1,1) NOT NULL,
[userid] [nvarchar](50) NULL,
[pair] [int] NULL
) ON [PRIMARY]
GO
my query is TRIGGER triggAfterUpdate is fired only when pair column in User_Details table is update only and when we update other column like ljoin or rjoin then my trigger is not fired
please any one can suggest us how it can done or provide solution
Jitendra Kumar Sr. Software Developer at Ruvixo Technologies 7895253402>select @userid=i.userid
frominserted i;
select
@pair=i.pair
frominserted i;
The code above assumes a single row UPDATE.
You have to setup the trigger for set processing like when 100 rows are updated in a single statement.
UPDATE trigger example: http://www.sqlusa.com/bestpractices2005/timestamptrigger/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
How to synchronize Sql Server when Oracle table has trigger
Hi
I have a trigger which will update/insert the data into a Oracle table.
I have an interface which normally moves the data from Oracle table to SQL Server table.
Is there any way which will update/insert the data into SQL Server table whenever any trigger fires on Oracle table.
Thanks,
GaneshODI's CDC capabilities can be used to propogate changes from Oracle to SQL Server. If your trigger inserts/updates on an oracle table, then ODI's CDC should pick that up. If you have a scenario which does a WaitForLogData on your Oracle table, it can kick off the interface to transfer the journal data whenever that happens.
-
hi,
Scenario : Insert into a table triggers a stored procedure on my DB (SQL 2000).
Question: Will the calling thread which initiated the insert wait for the stored procedure to end or will it make this as a back end process and return doing the insert.
KrishWill the calling thread which initiated the
insert wait for the stored procedure to end or will
it make this as a back end process and return doing
the insert.That depends. SQL Server returns results asynchronously, i.e. it returns update counts and ResultSets as soon as the query that generated them is executed. For example if you had a query/stored procedure that consisted of three SELECTs of which the first and third were really fast but the second was much slower, you would get the first ResultSet immediately, but when you called getMoreResults() it would have to wait until the second SELECT started returning at least the first few rows.
A trigger is usually executed before the INSERT/UPDATE/whatever so if you want the update count you will have to wait until the trigger finishes; there's no way around it. If you don't want the update count, then most SQL Server drivers have a "lastUpdateCount" parameter, which you can set to false to get update counts returned from inside triggers instead of the last update count, which is usually generated by your operation. But you will have to make sure your trigger does return an update count before it starts doing anything which may take long to finish.
Also, some drivers may take other approaches to ignoring update counts from triggers (which usually don't interest anyone), soch as not considering update counts returned from inside stored procedures (triggers are basically stored procedures). If the driver you are using does this, then you're out of luck.
As you can see, it's really difficult to say what will happen. The conclusion is pretty simple: don't do any heavy work in a trigger; find a way around it.
Alin,
The jTDS Project. -
Create Fiat File Using Trigger in SQL Server
Dear All,
How to Create a Flat File using Trigger in SQL Server?Take a look at osql/sqlcmd, bcp, COM calls, xp_cmdshell, etc. Here are a few links with code examples:
https://www.simple-talk.com/sql/t-sql-programming/reading-and-writing-files-in-sql-server-using-t-sql/
http://www.nigelrivett.net/SQLTsql/WriteTextFile.html
http://stackoverflow.com/questions/8132663/creating-a-text-file-on-local-machine-using-sql-server-2008
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Is sql server using trigger to capture change data in SQL server CDC?
hi all,
what is the Architecture of SQL server change data capture(CDC)? is sql server using trigger to capture change data in SQL server CDC? for example Change Data Capture (CDC) in SQL Server 2008 using we can capture change Data records INSERTs, UPDATEs, and
DELETEs applied to SQL Server tables.so my question is SQL server using triggers to capture change data like INSERT TRIGGER, UPDATE TRIGGER and DELETED TRIGGER using each tables after enabled CDC...?
Thanks
Tharindu Dhaneenja
Tharindu Dhaneenja http://dhaneenja.blogspot.comIt is not using triggers. The source is the transaction log.
Related link:
Basics of Change Data Capture
...The source of change data for change data capture is the SQL Server transaction log. As inserts, updates, and deletes are applied to tracked source tables, entries that describe those
changes are added to the log. The log serves as input to the change data capture capture process. This reads the log and adds information about changes to the tracked table’s associated change table. Functions are provided to enumerate
the changes that appear in the change tables over a specified range, returning the information in the form of a filtered result set. The filtered result set is typically used by an application process to update a representation of the source in some external
environment. ...
Kalman Toth, SQL Server & Business Intelligence Training; SQL Server 2008 Training -
Trigger problem on Sql Server with linked server to Oracle
Hi All,
I have a simple insert trigger on Sql Server 2005, it uses linked server to Oracle.
like that ;
USE [YTM08]
GO
SET QUOTED_IDENTIFIER ON
GO
ANSI_NULLS ON
go
ANSI_WARNINGS ON
CEATE TRIGGER [dbo].[YTM_TBLSTSABIT_I]
ON [dbo].[TBLSTSABIT] FOR INSERT
AS
BEGIN
INSERT INTO YTM_ORACLE..SECTOR.STOCKS
stock_name,
stock_code,
insert_date
SELECT
SBT.STOCKNAME,
SBT.STOCKCODE,
GETDATE()
FROM INSERTED SBT
END
The YTM_ORACLE is a linked server and it's provider is OraOLEDB.Oracle.
Trigger does not works for that linked server but other triggers for local
sql server works fine...
I get this error from sql server
'Heterogeneous queries require the ANSI_NULLS and
ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query.'
Does someone know how to solve this issue the right way?
Thanks in advance.
Thanks !
AdamHi Lars,
Thanks for the data. I've already read this note and configure all this parameters. But when I'm executing the Create Source System in the BI system the process dies.
If I look into the logs I see this:
M call semaphore clean-up function ...
M ***LOG Q0E=> DpSigGenHandler, Exception (c06d007e) [dpnttool.c 432]
That's the reason why I start guessing about other possible problem.
Regards -
SQL Server Express 2014 problem new trigger
Hello
I had use MS SQL Express 2012 Sql Server Management Studio.
After I installed MS SQL Express 2014 SSManagement Studio for 64-bit with ms sql server 2014.
But when use database in SSMS Express 2014 I can not use New Trigger button(it is gray) for sql server 2014( and also for 2008R2, 2012). But I can create with query, and with SSMS 2008 R2 Express or SSMS 2012 Express.
I don't understood this problem. But when install SSMS Express 2014, I test install SQLManagementStudio_x64_ENU, and SQLEXPRADV_x64_ENU - The SSMS can created, but New Trigger button is gray and not enable
Thanks helps
Stevemaybe you can check below url.
https://connect.microsoft.com/SQLServer/feedback/details/873249/ssms-2014-new-trigger-is-disabled-for-older-2012-2008r2-versions-of-sql-server
以上說明若有錯誤請指教,謝謝。
| 台灣 SQL PASS 社群 |
SQL PASS Taiwan
|
歡迎參觀我的BLOG - 積沙成塔 -
Sql Server High availability failover trigger
Hello,
We are implementing sql server 2012 availability groups (AG). Our secondary databases are not accessible in order to save licenses.
We have a lot of issues concerning monitoring, backup and SSIS. They all come down to the fact that they want basic information from the secondary, that is not accessible. We are implementing SSIS, which is supported on AG, but the SSISDB is encrypted.
Backup problem
The secondary instance does not know anything about the backups made in the primary instance. After a failover differential backups fail.
SSIS problem:
There is a blog (http://blogs.msdn.com/b/mattm/archive/2012/09/19/ssis-with-alwayson.aspx) that suggest to make a job that checks whether the status has changed from secondary to primary. If so, you can decrypt and encrypt again.
This job has to be executed every minute. Which is way too much effort for an event that happens once in a while. There are a few other problems with this solution. The phrase "use ssisdb" has to be included in the a job step. And the
jobstep fails. The secondary is not accessible.
Monitoring problems:
We use Microsoft tooling for monitoring: SCOM. Scom does not recognize a non readable secondary and tries to login continuously.
There are a few solutions that I can think of:
- sql server build in failover trigger
- Special status of secondary database.
Failover trigger:
We would like a build-in failover trigger, in stead of a time based job, that starts a few standard maintenance actions if only at the time (or directly after) a failover has occurred. Because now our HA cluster is not really high available until :
- SSISDB works and is accessible after failover
- Backup information is synchronised
- SCOM monitoring skips the secondary database (scom produces loads of login failures)
Does anyone have any suggestion how to fix this?No built in trigger can achieve your requirement.
-
Sql server 2008/2012 Trigger Query
Hi All,
I am trying to create a SLQ server trigger so that when TAS1 code is 003 then change the HRSCODE to OTHR. Would anyone be able to provide me with a sample code as to do this please ?Are you looking for something like the below code
IF OBJECT_ID('EMPLOYEE') IS NOT NULL
DROP TABLE EMPLOYEE
GO
/* Create employee table if it does not exist */
CREATE TABLE EMPLOYEE
EMPID INT PRIMARY KEY,
FNAME VARCHAR(25),
LNAME VARCHAR(25),
GO
/* Populate employee table with sample rows */
INSERT INTO EMPLOYEE (EMPID, FNAME, LNAME)
VALUES (500, 'John','Smith'),
(501, 'Alex','Admas'),
(502, 'Eric','James'),
(503, 'Shaun','Marsh')
GO
/* See the table records from both tables. We have four rows in both tables */
SELECT * from EMPLOYEE
CREATE TRIGGER TRG_InsertSyncEmp
ON dbo.EMPLOYEE
AFTER INSERT AS
BEGIN
UPDATE T1
SET FNAME='Jayaram'
FROM EMPLOYEE T1 WHERE EMPID=(SELECT EMPID FROM INSERTED where FNAME='Prashanth')
END
GO
INSERT INTO EMPLOYEE (EMPID, FNAME, LNAME) VALUES (505, 'Prashanth', 'jayaram')
select * from EMPLOYEE
--Prashanth
Maybe you are looking for
-
How to set up standalone wireless print server
I need step-by-step instructions on to set up a KonicaMinolta bizhub multifunction printer to print wirelessly from various Macs. In other words, it would not be hooked up to the internet or my wireless network. I understand this can be done with an
-
Windows 8 and no flash player!!
I have windows 8 and am really struggling to find my way around it, in fact, I hate it. My biggest annoyance is being unable to view videos that friends send or post on facebook. It tells me that I need to install flash player yet when I do it says t
-
Hi all I have a problem like this. Read a dictionary file . Search such a word which will have letter 'a' as its second letter , then remove the first two letters of the word. Now search the new word in the same dictionary file , if it is found..then
-
Hi, Is it possible to list information , that i have shared(i.e documents, sites etc) with external user.
-
IOS8 map app tells me to turn on Location Services which are already turned on
I am trying to use the iPhone map app. I tap an address in Contacts; the map app opens with a pin at the desired address. When I hit the car icon, I get a message: Turn On Location Services to Allow Maps to Determine Your Location Location Services