473,472 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trigger on a table in TempDB


I have an application that creates and makes use of a table in tempdb.
My problem is that I have a couple of triggers on this table that get
dropped everytime SQL Server restarts (due to the fact that tempdb gets
recreated). Is there a way to automatically recreate these triggers
each time SQL Server starts? It looks like it is not possible to have a
"create trigger" statement within a stored procedure. I would greatly
appreciate some ideas....thanks in advance!

Aug 21 '06 #1
3 1897
Am 21 Aug 2006 15:03:50 -0700 schrieb Karthik:
I have an application that creates and makes use of a table in tempdb.
My problem is that I have a couple of triggers on this table that get
dropped everytime SQL Server restarts (due to the fact that tempdb gets
recreated). Is there a way to automatically recreate these triggers
each time SQL Server starts? It looks like it is not possible to have a
"create trigger" statement within a stored procedure. I would greatly
appreciate some ideas....thanks in advance!
If you have a version with SQL-Agent, then you can define a job wich is
executed only once when SQLAgent starts. If this job cannot do a "create
trigger" and it is not possible with a stored proc too, then you can write
a batch file using OSQL or SQLCMD and create the trigger per command line.
The batch can be started by the job using xp_cmdshell. In the
job/batch/sproc you can check if the trigger exists, so it should not be a
problem to stop and start SQLAgent without restarting SQLServer.

bye, Helmut
Aug 22 '06 #2
Karthik (ka***********@gmail.com) writes:
I have an application that creates and makes use of a table in tempdb.
My problem is that I have a couple of triggers on this table that get
dropped everytime SQL Server restarts (due to the fact that tempdb gets
recreated). Is there a way to automatically recreate these triggers
each time SQL Server starts? It looks like it is not possible to have a
"create trigger" statement within a stored procedure. I would greatly
appreciate some ideas....thanks in advance!
You can say:

EXEC ('CREATE TRIGGER ...')

in your stored procedure (that you would set up as a start-up procedure
for the server).

However, the design sounds dubious to me. Why have the table in tempdb?
Why not in a user database?
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Aug 22 '06 #3

Erland Sommarskog wrote:
Karthik (ka***********@gmail.com) writes:
I have an application that creates and makes use of a table in tempdb.
My problem is that I have a couple of triggers on this table that get
dropped everytime SQL Server restarts (due to the fact that tempdb gets
recreated). Is there a way to automatically recreate these triggers
each time SQL Server starts? It looks like it is not possible to have a
"create trigger" statement within a stored procedure. I would greatly
appreciate some ideas....thanks in advance!

You can say:

EXEC ('CREATE TRIGGER ...')

in your stored procedure (that you would set up as a start-up procedure
for the server).

However, the design sounds dubious to me. Why have the table in tempdb?
Why not in a user database?
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Thanks Helmut and Erland! It had to be a SQL Agent job---Apparantely
cannot have a SP in the master db to create a trigger on the tempdb.

Aug 22 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Manoj S. P. | last post by:
Hi Folks, My basic requirement is I want to write a trigger on a table based on certain conditions post-update from another table in another database. The actors in this scenario are:...
4
by: Steve Bishop | last post by:
I have an Insert, Update and delete trigger on a table that works fine. It records the changes into another table called tblTracking. tblTracking records the changes so they can be uploaded to...
8
by: Jason | last post by:
I have a table that matches up Securities and Exchanges. Individual securities can belong on multiple exchanges. One of the columns, named PrimaryExchangeFlag, indicates if a particular exchange is...
3
by: Rebecca Lovelace | last post by:
For some reason in Enterprise Manager for SQL Server 2000, I cannot put the following line into a trigger: select * into #deleted from deleted When I hit the Apply button I get the following...
1
by: T.S.Negi | last post by:
Hi, Handling # table is giving problem. Does anybody have solution/suggestion for the below given problem. Create a #TMPTAB table ------------------------ SELECT GETDATE() MYDATE INTO...
4
by: Pecos Bill | last post by:
Salve, non riesco a disabilitare un trigger su sqlserver nč da query analyzer, nč da enterprise manager. In pratica tal cosa riuscivo a farla in Oracle con TOAD, mentre qui non riesco. Mi...
6
by: pb648174 | last post by:
I have a pivot table implementation, part of which is posted below. It returns no errors in query analyzer, but when profiler is run, it shows that "Error 208" is happening. I looked that up in BOL...
2
by: Dima Gofman | last post by:
I have a trigger on UPDATE on a table. I'm running some maintenance UPDATE and DELETE queries which I want the trigger to ignore but at the same time I want other UPDATE queries that other users...
6
by: sql_server_user | last post by:
I'm trying to copy all 440 million rows from one table in my SQL Server 2005 db to another table with a different clustering scheme. After a few test inserts that were successful (up to a million...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.