Can I dropped triggers and recreate them? Dropped is easy but I dont know how to recreate them. I need separate proc to drop and recreate triggers to avoid deadlock issues in package.
drop triggers---
CREATE PROC [dbo].[SP_DropTriggers]
AS
BEGIN
DECLARE @Table_Triggers SYSNAME, @trName sysname
DECLARE Cursor_Disabletriggers CURSOR FOR
SELECT object_name(parent_id) , name
FROM sys.triggers
OPEN Cursor_Disabletriggers
FETCH NEXT FROM Cursor_Disabletriggers
INTO @Table_Triggers ,@trname
DECLARE @SQL nvarchar(max)
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL = 'drop trigger ' + 'dbo.'+@trname + ' on dbo.'+@Table_Triggers
select @sql
EXECUTE (@SQL)
FETCH NEXT FROM Cursor_Disabletriggers INTO @Table_Triggers ,@trname
END
CLOSE Cursor_Disabletriggers
DEALLOCATE Cursor_Disabletriggers
END
I would like to recreate them in separate proc, How can I achieve this?
You need a permanent table to store the trigger code in:
create table
dbo.TriggerDefinitions
(TableName nvarchar(128) not null,
TriggerName nvarchar(128) not null,
TriggerDefinition nvarchar(max) not null,
constraint PK_TriggerDefinitions primary key (TableName, TriggerName))
go
In your procedure which drops the triggers you need to add code that stores the latest trigger definitions in the table above:
create procedure dbo.DropTriggers
as
begin
declare @TableName nvarchar(128),
@TriggerName nvarchar(128),
@TriggerDefinition nvarchar(max),
@DynamicSQL nvarchar(max)
declare TriggerCursor
cursor fast_forward for
select quotename(object_schema_name(po.object_id)) + '.' + quotename(po.name),
quotename(object_schema_name(co.object_id)) + '.' + quotename(co.name),
m.definition
from sys.sql_modules as m
join sys.objects as co
join sys.objects as po
on po.object_id = co.parent_object_id
on co.object_id = m.object_id
where co.type = 'tr'
open TriggerCursor
fetch next
from TriggerCursor
into @TableName,
@TriggerName,
@TriggerDefinition
while @@fetch_status = 0
begin
if exists(select top 1 1 from TriggerDefinitions where TableName = @TableName and TriggerDefinition = @TriggerDefinition)
update TriggerDefinitions
set TriggerDefinition = @TriggerDefinition
where TableName = @TableName
and TriggerName = @TriggerName
else
insert TriggerDefinitions
values (@TableName, @TriggerName, @TriggerDefinition)
if @@rowcount = 1
begin
set @DynamicSQL = 'drop trigger ' + @TriggerName + ' on ' + @TableName
print @DynamicSQL
--execute sp_executesql
-- @DynamicSQL
end
fetch next
from TriggerCursor
into @TableName,
@TriggerName,
@TriggerDefinition
end
close TriggerCursor
deallocate TriggerCursor
end
go
Finally the procedure which will re-create the triggers will simply query the table created and populated above and execute the code contained therein.
create procedure dbo.CreateTriggers
as
begin
declare @TableName nvarchar(128),
@TriggerName nvarchar(128),
@TriggerDefinition nvarchar(max),
@DynamicSQL nvarchar(max)
declare TriggerCursor
cursor fast_forward for
select *
from dbo.TriggerDefinitions
open TriggerCursor
fetch next
from TriggerCursor
into @TableName,
@TriggerName,
@TriggerDefinition
while @@fetch_status = 0
begin
set @DynamicSQL = @TriggerDefinition
print @DynamicSQL
--execute sp_executesql
-- @DynamicSQL
fetch next
from TriggerCursor
into @TableName,
@TriggerName,
@TriggerDefinition
end
close TriggerCursor
deallocate TriggerCursor
end
go
I've commented out the code which actually runs the dynamically created SQL. You'll have to uncomment those lines for the code I've posted will work.
Similar Messages
-
please help me try to contact the owner of this phone IMEI **** ICCID **** i got his phone now with me but i dont know how to contact them first time i got it low battery contact me
I will explan more how i got this phone
Call me +**** Micky Thai
<Personal Information Edited By Host>A long shot but you might try using the phone to send an email to the phone asking the owner to call their mobile phone. If the owner has a computer they may get the email and get in contact with you.
But Roger's suggerstion of turning it over to the police is the best bet.
OT -
hi ive got a ipod nano 7G and i have downloaded and game from the app store on to the computer but i dont know how to put it on my ipod!
thanks!Ipod nano 7th Gen is not compatible to any games in apps store. It is not an IOS device so no application can be installed in your nano. Cheers!
-
While updateing my computer with firefox, I seen something about debian come up on the screen and fallowed the instructions. I didn't know what I was doing. Now I'm using iceweasle and I want my old set up back. I want to uninstall. debian and reinstall umbuntu, but dont know how. I am new to Computers.(sad I know) Please help!
Contact iTunes support: https://getsupport.apple.com/Issues.action
-
I upgraded the version of iTunes about a week ago but have not logged on since. when trying today I have received the following message -
"This version of iTunes has not been correctly localized for this language. Please run the English version".
I though I would try to update the version from the Apple site but to do so I have to log into iTunes which is the problem.
Any help would be greatly appreciated!
Thanks,
RonnieStart by trying to repair iTunes from the programs and features control panel.
Otherwise, for general advice see Troubleshooting issues with iTunes for Windows updates.
The steps in the second box are a guide to removing everything related to iTunes and then rebuilding it which is often a good starting point unless the symptoms indicate a more specific approach. Review the other boxes and the list of support documents further down page in case one of them applies.
Your library should be unaffected by these steps but there is backup and recovery advice elsewhere in the user tip.
tt2 -
ok so lately someone has been trying to phish my computer but i cant really do anything about it. I cant use Youtube and it sometimes doesnt let me go on any social networking sites. Is it possible for me to report these people to the police for tampering with my computer? And how can i make sure they stop
HellO:
Is it possible for me to report these people to the police for tampering with my computer
As far as I know, phishing is not a criminal act. If you fall for it, you might be considered less than the brightest bulb in the lamp.
Phishing is a common problem for most of us. In my case, I report it to the web site involved ( a bank, for example) for their follow up.
Barry -
I have lost my "notes" from my phone, PC, ipad and when i go into backup i cant find them , any help would be appericated....
Hi t.romano91,
Welcome to the Support Communities!
I'm not sure why you had to manually enter your contact information, but if you created and turned on your iCloud account, the information should be there.
The link below will give you a general overview of iCloud, and how to look at your contacts:
iCloud Help: Contacts overview
I've also included the User Guide for the iPhone below to help you get started ...
Please note that the Contacts App (looks like a brown address book) is located inside the Utilties folder on your home screen. Press and hold the Utilities folder and it will jiggle. Then drag the Contacts App out onto the home screen for easier access. (see page 20 of the guide below).
manuals.info.apple.com/en_US/iphone_user_guide.pdf
Page 100 - 102 explains how the Contacts feature works.
Enjoy your new iPhone!
Have a great day!
- Judy -
HT201472 hi there i have lost my iphone and i want to find it but i dont know how?
hi
Provided you have Find My iPhone configured before you lost it and the iPhone has Internet connection,
to locate use you computer browser with this link: https://www.icloud.com/#find
If you cannot track it, report to the police, insurance, carrier and change all your passowrds that were used in iPhone.
Lost or Stolen
http://support.apple.com/kb/HT2526 -
I have rented some movies and have them in itunes. I want to move them to my iphone but don't know how can someone help?
http://support.apple.com/kb/HT1390
Regards. -
i have lost all my notes saved on my iphone after syncing it. and my default mailbox is gmail. notes were very important. and now i dont know how to get them back. can anyone help me out please? thanks in advance.
Try this ..
On your Mac open System Preferences > iCloud
Deselect the box next to: Notes
Then reselect it.
Give iCloud a few minutes to re sync the data.
Other than that, try Time Machine > http://pondini.org/TM/15m.html -
I recently downloaded Ios 7 and all the songs that i have purchased before, but deleted off my itunes because i didn't want them, showed up. I don't know how to delete them off my ipod and i really don't want them there. Is there a way to get them off? The songs dont show up in my itunes on my computer, just on my ipod with a download button next to them. I don't want them there anymore because i don't like that kind of music anymore and i don't know how to get them to go away.
There is a similar setting for Videos on that Settings screen, so if you leave that 'on' you may have similar happening in the Videos app
-
I recently purchased songs from itunes via my pc and I dont know how to get them onto my iphone? When I click the sync button it says I will lose all the music currently on my iphone.. Help
If you're syncing with a different iTunes library than the one you previously synced with, then there is no way around it. You're gonna loose the old data. The only way round it would be to make sure that all the music files on your iPhone is also in your iTunes library. If you still have access to the computer with the old library, you could copy the files on to an external harddrive, and then import them into your new iTunes library.
If it is in fact the same library, then the music currently on your iphone, is also in your itunes library. Just make sure that the artists/albums/playlists, or whatever you sync contains these tracks, that you allready have on your phone and don't want deleted. What i do is, i create a playlist specifically for my iPhone, and i set it up to only sync with this playlist. Whenever i hear a track from my iTunes library or buy a new track that i want on my phone, i just drag it to this playlist and next time i synchronize, it's there without deleting anything else. -
After upgrading my software i have seem to have lost all my contacts and photos, i did a back up but i have no idea how to get them back on? maybe im illiterate but i dont know how to find it in my itunes? please help!!
http://support.apple.com/kb/HT5824?viewlocale=en_US&locale=en_US
-
I keep taking screen shots but they dont show up on my desktop and i dont know how to find them
helppp
i keep talking screen shots but they dont show up on my desktop and i dont know how to find them!I have the same problem. One of the reliable things about Apple OSX, that we could count on screenshots being simple. Then DropBox came along. I suspect DropBox is the culprit here. I don't mind, even am grateful if DB captures my captures, but who gave them permission to totally changes my whole universe!!?
-
so my computer crashed and i had lost all my itunes purchases and dont know how to get them back, so my computer crashed and i had lost all my itunes purchases and dont know how to get them back
You have a backup of your computer, or at the very least of your iTunes media, correct?
Simply copy your backup of your iTunes media into the iTunes library on your new computer.
Connecting and syncing your device to the new computer without first recovering your iTunes media is a really, really, really bad idea. iDevices are designed to ONLY sync with one computer. When you plug your device into a new computer, it will wipe all media on the device when it syncs. The only media you may be able to salvage and transfer to the new computer would be anything bought directly on the device.
If you do not have a backup of your iTunes media, then you will want to either look at a way (using software from a third party company) to either extract the media from you iDevice or your old computer (assuming the hard drive is not toast).
Maybe you are looking for
-
Hi, When I am trying to run Financial Reports in workspace getting the following erroer. *5200: Error executing query: Java.lang.ArithmeticException: / by zerojava.lang.ArithmeticExceptoion*. the issue with the only Planning reports. Consolidation re
-
JDK error in SolMan 7.0 installation
I am installing SAP Solution Manager 7.0 on Windows 2003 Server R2 Enterprise x64 and Oracle 10.2.0.4 Patch 8 During the installation its asking me to install a JDK and enter the location. But when I give the path C:\j2sdk1.4.2_12 it says this JDK do
-
When deploying BPEL Process through JDeveloper java.security.AccessControlE
1.) Navigated to the Connections tab of JDeveloper 10.1.3.2. 2.) Under the Application Server node, created a new Application Server connection, provided the relevant information on Type, Authentication & Connection's tab. 3.) On Authentication Tab,
-
Has Anyone Seen This Display Problem Before?
This is a picture of the display from my sister's Power Mac G5. She installed 10.5.5 from the software update today. She said she was editing a document in Pages and all of a sudden it displayed this weird color pattern. http://www.pixelsandbits.net/
-
How can I make the newest version of iTunes for Windows run faster?
I know I'm not the only one when I say that iTunes is by far one of the slowest programs on my computer. I'm running Windows 7 and running the most recent version of iTunes for Windows. Does anyone have some tips to make it run faster and smoother?