Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Run stored procedure when temp table is created/dropped Expand / Collapse
Author
Message
Posted Monday, January 21, 2013 4:33 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:05 AM
Points: 14, Visits: 67
Hi guys and girls,

I need to update 1 or 2 records in my database each time a temp table with the name like '##ABC_%' is created/dropped.
(Note: Temp tables are created from my application.)
I can do this in my application (VB.NET), but I didn't wrote it and the guy before me didn't understand multi-tier/OO.
So I want to move the update part to the SQL Server (if possible).
Is there a way in SQL2005 to detect the creation/deleting of a temp table and then run a SP?

All ideas/thoughts are welcome.

Grtz
Jo
Post #1409477
Posted Monday, January 21, 2013 10:26 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, July 26, 2014 8:57 AM
Points: 7,081, Visits: 12,575
I checked to be sure and DDL triggers FOR CREATE_TABLE do not fire when a global temp table is created. I do not know of way to accomplish what you're after.

__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1409643
Posted Monday, January 21, 2013 12:20 PM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 18, 2014 10:48 AM
Points: 1,935, Visits: 10,956
You could do this with SQL Server Integration Services (SSIS) running on a tight schedule (every few minutes?) or with SSIS and the FileWatcher task (available from www.sqlis.com), which will detect changes to folders on the server.

Edit: Sorry, I may have mis-read your post. You're looking at temp tables, not files dropped to a folder. My solution probably won't solve your problem then.


Rob Schripsema
Accelitec, Inc
Post #1409675
Posted Tuesday, January 22, 2013 1:43 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:05 AM
Points: 14, Visits: 67
Thanks for the replies.

Does any one else have an idea how to solve this?

grtz
Jo
Post #1409863
Posted Tuesday, January 22, 2013 11:27 AM


SSCommitted

SSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommittedSSCommitted

Group: General Forum Members
Last Login: Friday, July 18, 2014 10:48 AM
Points: 1,935, Visits: 10,956
I did explore this further yesterday and wondered about your apps architecture. You could create these global temp files (##ABC) and look through the tempdb.sys.tables table to locate them, but they will only exist for as long as there exists a connection that references them. So, if your VB app creates them, writes to them and then disappears (dropping the connection), the file(s) will be dropped also.

But, if the VB app is continously running and keeping the SQL connection open, you could create a 'polling' job that would execute every N minutes/seconds that would query tempdb.sys.tables for entries for temp file names that match your pattern. So, your update process wouldn't be 'triggered' by an event, but would be 'discovered' by a process that goes out and checks (polls) for data.

Then you'd probably have to use some dynamic SQL to actually query those temp tables to get the data out of them for your update process.

Not sure I'd agree that this is the most robust architecture, but I suppose it depends on your system and your situation.


Rob Schripsema
Accelitec, Inc
Post #1410191
Posted Tuesday, January 22, 2013 12:38 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:35 PM
Points: 12,887, Visits: 31,832
i am wondering if you could put an extended event for CREATE_TABLE on the tempdb?

I'll grab one of my sample extended events and try it, but it's just an idea for now;

i'd think that the extended event would be destroyed on start/stop of the server, so you'd need something that keeps adding it back, if an extended event is even allowed.


Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1410228
Posted Tuesday, January 22, 2013 1:56 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Saturday, July 26, 2014 8:57 AM
Points: 7,081, Visits: 12,575
Lowell (1/22/2013)
i am wondering if you could put an extended event for CREATE_TABLE on the tempdb?

I thought of that too, but it's SQL 2005.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1410262
Posted Wednesday, January 23, 2013 8:55 AM


SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Tuesday, July 22, 2014 2:33 PM
Points: 139, Visits: 614
Hm. Maybe using SQL Profiler? Trap all "CREATE TABLE #" commands? ...just a thought...
Post #1410643
Posted Monday, January 28, 2013 8:44 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, March 13, 2013 4:05 AM
Points: 14, Visits: 67
Hi,

It seams to be not that easy/possible to catch this at server-side.
I'm going to dig into the code and seach for those temp tables (and centralize it ).

Thanks for the help on this topic.

grtz
Jo
Post #1412479
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse