How To Force Immediate Recompile Of Triggers And Detect Errors?

Mar 23, 2006

I need a way to programmatically (via JDBC) find out which triggers for a table may not compile properly, so that I can disable the bad triggers.

I can do this fine in Oracle but cannot figure out if there's a way to do this in SqlServer. (In Oracle I'd just "alter trigger... compile" and select from user_errors.)

I know how to find the triggers that exist on a table, and I know how to enable/disable individual triggers. I know about sp_recompile, but all that does is flag the trigger for recompile at the next execution.

I need to verify whether the trigger is valid without having to actually invoke it. For example, if there's a bad Update trigger, I don't want to actually execute an update on the table.

One example of what I'm dealing with is this... We have Table A and Table B. There is an update trigger on Table B that references column A.col1. Then we alter Table A to drop col1. Later we have to update Table B. At this point the update will fail because of the bad trigger. I want to find and disable the trigger before executing the update on Table B. If there are other triggers on Table B that are valid, I want to leave them alone.

View 2 Replies


ADVERTISEMENT

Force SQL Server To Recompile Stored Procedures Every Time They Run (SQL Server 7/2000)

Apr 27, 2005

This is a solution for a very specific problem, and it's one that you'll hardly ever use, but it's important to know about that one scenario where it can save your neck. Ordinarily, stored procedures are only recompiled if they're no longer in the procedure cache. But if a stored procedure's execution plan is still in the cache, then SQL Server reuses the compiled storedprocedure and its existing execution plan. This is almost always the best course of action. Almost always, but not always.Sometimes, however, reusing an existing plan doesn't offer the most efficient performance. Imagine, for example, that your stored procedure accepts a parameter that determines the natureof a JOIN operation. The results can vary in a big way, so you wouldn't want your procedure to be locked into an execution plan that might be completely inappropriate for that JOIN. In a highlyspecialized case like this, you might want to force SQL Server to recompile the procedure every time the procedure runs. Doing so comes at a performance cost, but this might be offset by thesavings you gain in not executing the procedure with an awful compiled execution plan. Consider carefully whether to use this approach (or whether to re-engineer the over-design of yourapplication to avoid this situation in the first place). Should you need to instruct SQL Server to recompile each time, add the WITH RECOMPILE directive to the procedure, like this:    CREATE PROCEDURE ProcName        @Param int /* ... other parameters */        WITH RECOMPILE    AS /* ... procedure code follows */
If we omit "WITH RECOMPILE", what will be the consequence? Thanks
 

View 3 Replies View Related

A Way To Force SQL Server To Ignore Errors On DTS Import?

Nov 11, 2004

Hello - the very nature of this question seems to make no sense I know - but we received a huge volume of data (29 tables) in flat file format. I first imported them into MS Access because of its portability and it seemed to be more forgiving on imports. Now I have a complete MS Access DB with all tables, so I figured importing to SQL server should be a snap. However, on the import, I had 14 tables import successfully, and 15 failed!

Here is an example of one of the error messages I received:
Insert Error, Column 3 - status 6; Data Overflow...this was on a date/time field in access, and here is the data contained in the referenced row/column: "8/19/4999"

the year "4999" is obviously the problem (at least i think), and I have no idea why this successfully imported to MS Access, but not to SQL Server....

what i'd like to be able to do (not the best practice, i know) for now is ignore these types of errors - and just force SQL server to take the data straight from MS Access and replicate it. We received this data from a 3rd party, and there's no telling how many data entry errors like this could be in each table - many of the tables have over 500,000 rows, and i don't want to have to go through fixing each of these errors by hand...anyone have any ideas?

View 1 Replies View Related

Force To Complete Query, Ignore Errors

Nov 9, 2006

Hi,

I have a big table and want to make a plausibility check of it´s data.

Problem is, that my query stops, if there is an unexpected datatype in one of the rows. But that is it, what i want to filter out of my table with that query and save the result as new correct table.

How can i write a parameter to my query SQL Code, that if a error occurs, the querry resumes and the error line will not displayed in my final querry overview?

In my books and on the net, i don´t found something to this theme ;-(.

Thx in advance.

View 9 Replies View Related

How To Force A SQL Server Job To Always Succeed Even When SSIS Packages Have Errors

Jan 11, 2008


I have added an email task to the ON Error Event of my SSIS package, so that I will always know when there are errors.
However I would like the SQL Server job executing the package to succeed even if the package fails.
What setting do I change in the SSIS packageto achieve this? MaximumErrorCount?




View 1 Replies View Related

Anyway To Force SQL Server To Save Store Procedure With Errors?

Feb 12, 2008

When I create/alter a store procedure in SQL Server 2005, SQL server always checks for syntax errors first and won't let me save the change if it detects any error. Is there a way we can force the SQL server to save the store procedure that fails the syntax check?



I know SQL server will allow such invalid store procedures if you detach & re-attach the entire database from one SQL server to another server. However, if I try to manually create the same store procedure from one server on a different server with a script, then it won€™t let you save the store procedure if the linked server (or the table) can€™t be accessed from the new sql server.



How do you get around this?





Thanks

View 13 Replies View Related

No Recompile After Sp_recompile Or WITH RECOMPILE Option

Aug 30, 2007

I know that all the documentation always tells you that sp_recompile will force a stored procedure to recompile the next time it is executed. However, I am not seeing the recompiles in a SQL Trace, when capturing SP: Recompile events. I have tried this on many different database servers, using sp_recompile and also the WITH RECOMPILE option when creating the proc.

Can anyone explain this?

View 4 Replies View Related

Errors And ROLLBACKs In Triggers

Nov 28, 2007

Hello,

I'm using SQL Server 2005 Express. I have this task I've been trying to solve:





Code BlockCREATE TABLE A


(
a INT UNIQUE
)
What I want to do is to create an AFTER INSERT trigger on A that inserts 2*a and 3*a for each inserted a. As the a column is UNIQUE, errors might occur. The trigger is to a) ROLLBACK the whole transaction b) if the error occurs when inserting a, then ROLLBACK insertion of 2*a and 3*a. The trigger is suppsed not to check whether 2*a or 3*a are in A already.

The first one seems easy:





Code Block

CREATE TRIGGER InsTr ON A
AFTER INSERT
AS
BEGIN
BEGIN TRY
INSERT INTO A SELECT 2 * a FROM inserted
INSERT INTO A SELECT 3 * a FROM inserted
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH
END
GO

DELETE FROM A
GO

BEGIN TRAN
INSERT INTO A VALUES (4) -- insert 4, 8, 12
INSERT INTO A VALUES (2) -- insert 2, 4, 6
INSERT INTO A VALUES (1) -- insert 1, 2, 3
COMMIT
GO

But I can't seem to get the second right:





Code Block

DROP TRIGGER InsTr
GO

CREATE TRIGGER InsTr ON A
AFTER INSERT
AS
BEGIN
SAVE TRANSACTION Wst
BEGIN TRY
INSERT INTO A SELECT 2 * a FROM inserted
INSERT INTO A SELECT 3 * a FROM inserted
COMMIT TRANSACTION Wst
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION Wst
END CATCH
END
GO





DELETE FROM A
GO




BEGIN TRAN
INSERT INTO A VALUES (4) -- insert 4, 8, 12
INSERT INTO A VALUES (2) -- insert 2, 4, 6
INSERT INTO A VALUES (1) -- insert 1, 2, 3
COMMIT
GO


The result is that the A is missing values 1, 2. How to solve this?

View 9 Replies View Related

7.0 Recompile.

Sep 13, 2000

We have lots of stored procedures containing temporary tables. In SQL 6.5 every thing was great. But in 7.0, it's doing a lot of recompile while executing. Tried trace flag 8720, didn't work..

Basically I am talking abt this problem :
http://support.microsoft.com/support/kb/articles/Q224/5/87.ASP

Let me know if any ideas/Remedies ??? How did any of you tackled this behaviour.

View 1 Replies View Related

Option (RECOMPILE)

Oct 25, 2007

Hi,
What is equivalent to OPTION (RECOMPILE) in SQl Server 2000.  
Create table #Employee
(
EmpId int IDENTITY,EmpName varchar(30)
)
insert into #Employee(EmpName )
select EmpName from AllEmployees
OPTION (RECOMPILE)

View 1 Replies View Related

EXECUTE… WITH RECOMPILE

Jun 2, 2002

What exactly does WITH RECOMPILE do? I read that it will create a new plan. I guess the next question is, what is the purpose behind that?

Can someone explain to me?

Thanks

View 2 Replies View Related

Reload Or Recompile

Oct 30, 2000

Does someone know whether it is better to drop and reload or sp_recompile a stored procedure to get a new, recompiled execution plan? I have another DBA telling me it is better to drop and reload the stored procedure rather than use sp_recompile. I would think that sp_recompile would be the preferred method.

View 1 Replies View Related

RECOMPILE / REFRESH UDF?

Dec 19, 2007

Is there a way (command or stored procedure) to RECOMPILE or REFRESH a USER DEFINED FUNCTION? I can recompile SPs with sp_recompile and refresh views with sp_refreshView, but I could not find any way to refresh User-defined functions (some of them are like views, with parameters).

Environment: SQL 2005 SP2.


Thanks !

View 4 Replies View Related

Sp:Cachemiss And No Sp:recompile

Jul 20, 2005

Hello:The installation details:W2K SP4, SQL Server 2000 Ent with 1GB RAM. It is a Bi-P3.When I run the Profiler to trace Stored Procedure performance, I get abunch of SP:CacheMiss for couple of stored procedure I invoke quiteoften in a web app.But I do not see SP:Recompile.Here are my questions:i) If the plan is not in the Cache, why am I not see SP: Recompile.Where else can it be tugged.ii) What are the other counters I need to monitor to see if I need morememory.Thanks in advance for any leads on this.Regards:

View 4 Replies View Related

Using Recompile On Stored Procedures

Aug 10, 2000

If my data structure never changes, just the data itself, is
there a need to use the "with recompil option" on stored
procedures? Isn't there a performance hit having it in
the stored procedure?

Thanks

View 1 Replies View Related

Performance Question: Recompile

Dec 29, 1999

What's the performance hit for using 'WITH RECOMPILE' in a stored procedure? I'm not a serious DBA, nor do I pretend to be one, but I'm writing a sp_ to be used with both insert and updates. I'm using a variable that defines the operation (IF @operation = 'Update'...) which will be passed at run-time from ColdFusion. Do I need to use the 'WITH RECOMPILE' clause to keep the sp_ kosher with respect to the operation being performed? And what's the damage in resources?

Thanks,

John E.

View 3 Replies View Related

Recompile Stored Procedure?

Jun 15, 2000

How to recompile a stored procedure automatically in SQL server 6.5?

Thanks in advance

Stella

View 1 Replies View Related

Recompile Stored Procedure

Jun 15, 2000

Does the SQL Server 6.5 system recompile all stored procedures automatically when the server is restarted?

Thanks.

Stella

View 1 Replies View Related

With Recompile In Stored Procedure

Aug 20, 2004

Hi,

currently i am working on performance tuning on some stored procedure and found that most of the stored procedure include with recompile on top of it.

i try to remove it and now it improve a lot on speed tuning. However, for those stored procedure which is using dynamic sql, is it a must to include recompile in our stored procedure?

View 10 Replies View Related

How To Recompile / Refresh UDFs ?

Mar 6, 2007

Hi!I need to refresh an entire database.I can recompile SPs with sp_recompile (or DBCC FLUSHPROCINDB), andrefresh views with sp_refreshView, but I cannot find any way torefresh my user-defined functions (some of them are like views, withparameters).Any help appreciated :) !Ben

View 5 Replies View Related

Auto Recompile In Sql Server

Jul 20, 2005

Hi,I have a question in SQL Server 2K, I use SQL Profile to trace, andfind Stored Procedure was auto recompiled, like this row in thetrace:SP:Recompile151680762004-02-27 16:01:11.610How can I stop the auto recompile.ThanksHarold

View 7 Replies View Related

Recompile Of Stored Procedures - URGENT

Apr 11, 2001

We are developing a production/management solution for the photo finishing sector. We need a performance of 1 order priced per second.
If we run the procedure once we dont have a dramatical performance loss due to recompilation of the stored procs.
If we have about 3 consecutive sessions we find the performance loss to be at a rate of about 200 - 500 %.
We can't afford this. On the site of msdn we found some reasons why sql server needs to recompile, but since the structure of our db can't be changed in such a manner that this would resolve the problem we need an alternative.
All help is greatly appriciated.

View 4 Replies View Related

Recompile All Stor Proc And Udf And Views

Oct 1, 2003

Hi ,
what would be correct way to recompile
all user objects ?

Developers working by using alter create and rename on udf and stored procedure, dependecicies window in EM does not repesent correct info.

If I want to see up to date all dependedcies of every user defined object in db

Thank you


Alex

View 5 Replies View Related

Stored Procedure Timing Out Until Recompile

May 17, 2007

Hey all,

We have a problem with one of our MS SQL 2000 databases and some stored procedures.

I'm not sure exactly what the problem is, but these are the symptons....

The stored procedure runs without problems for a period of time. Abruptly, without warning it begins to time out when called from our web application.

Calling it through the query analyzer it runs within a second.

Forcing the stored procedure to recompile allows the web application to start calling it again without it timing out.

We have a DTS package that runs over night and imports a number of records (not sure on the exact numbers, but definately enough to make a difference to indexes) so this could be part of the problem although when I force a recompile I do not do any update stats or anything else.

I wrote a test script to call the stored procedure when it was timing out to ensure it wasn't a web application problem and the procedure continued to time out until the forced recompile. So I don't think the problem is there.

The stored procedure returns multiple results sets and when it starts timing out it is while it is returning the second results sets.

The code for the second results set is...


Select avg(round(p.PricingValue, 5)) as Average, stdev(round(p.PricingValue, 5)) as StdDev, min(p.CaptureDate) as FromDate, max(p.CaptureDate) as ToDate
From Pricing p
Inner Join Security s
On p.SecurityID = s.SecurityID
Left Outer Join Issuer i
On s.IssuerID = i.IssuerID
WHERE p.PricingTypeID = @PricingType
And p.TenorTypeID = @TenorType
And p.CaptureDate Between @DateFrom And @DateTo
AND p.SecurityID IN ( SELECT SecurityId FROM UserResult ur WHERE ur.UserResultSelected = 1 AND ur.UserID = @userID )


Does anyone have any idea what might be going on here?

Regards
Shaun

View 13 Replies View Related

Can We Recompile View Instead Of Drop And Create

Jan 31, 2008

Hi,
I increased one of my base tables column which is referenced in view

I noticed sql server didn't recognized this change and its still showing old field size in the view.

I can simply drop and create it again. But wanted to know if there is any way (command/sp) to recompile the view which will be easy to deploy in production as patch.

Thanks
- D

View 11 Replies View Related

OPTION(RECOMPILE) And Execution Plan

Jan 23, 2008



Hi,


I use recompile option in SQL query to dynamic pass variable to optimizer.

I verify explain plan with SET STATISTICS PROFILE ON

and optimizer chose nested lookup ,ok. But if use Display Estimated Execution Plan (CTR+L) I€™ve get merge join. It€™s very confusing, some suggestion €¦?


Use AdventureWorks

go

declare @StartOrderDate datetime

set @StartOrderDate = '20040731'

SELECT * FROM Sales.SalesOrderHeader h, Sales.SalesOrderDetail d

WHERE h.SalesOrderID = d.SalesOrderId

AND h.OrderDate >= @StartOrderDate

OPTION(RECOMPILE);

SQL2005SP2


djedgar

View 4 Replies View Related

Views Containing SELECT * Do Not Recompile When Table Is Modified

Mar 17, 2008

If I have a view such as: SELECT T.* FROM T
When I add a column to table T the view is not updated to reflect that change.
Furthermore, if there are other columns after the * in the view (for example SELECT T.*, GETDATE() as "My Date" FROM T) the last columns will contain incorrect data.

Is there a work around for this? An "auto-recompile when tables are modified" kind of option?

Thanks
Nick

PS: This is the script I used for testing:

create table tt (
test1 int primary key,
test2 int)
go
insert into tt (test1, test2) values (1,2)
go
create view vw_tt as select *, getdate() as "My Date" from tt
go
select * from vw_tt
go
create view vw_tt2 as select * from tt
go
alter table tt add test3 int
go
select * from vw_tt
select * from vw_tt2
select * from tt
drop table tt
drop view vw_tt
drop view vw_tt2

View 9 Replies View Related

Multiple Triggers On A Table Or Encapsulated Triggers

May 12, 2008

This isn€™t an problem as such, it€™s more of a debate.

If a table needs a number of update triggers which do differing tasks, should these triggers be separated out or encapsulated into one all encompassing trigger. Speaking in terms of performance, it doesn€™t make much of an improvement doing either depending upon the tasks performed. I was wondering in terms of maintenance and best practice etc. My view is that if the triggers do totally differing tasks they should be a trigger each on their own.

www.handleysonline.com

View 12 Replies View Related

SQL Server 2008 :: Need To Recompile Stored Procedure After A Table Alter?

Feb 5, 2015

Version 2008 R2

The stored procedure has the dependency on the table that was altered.

View 4 Replies View Related

Transact SQL :: Placement Of Option (Recompile) In Dynamic For XML Select Statement?

Apr 18, 2015

I can't seem to place the "option (recompile)" in any valid position so that the following procedure executes without a syntax error .

USE [PO]
GO
/****** Object: StoredProcedure [dbo].[npSSUserLoad] Script Date: 4/18/2015 3:57:38 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON

[Code] ...

-- Generated code - DO NOT MODIFY

-- From Object Schema: 'C:XXXXXX.NetPOPOModel\_ObjectSchema

-- To regenerate this procedure use the 'Open With' option on file _ObjectSchema and select POCodeGen.exe

Declare @SqlCmd nvarchar(max)
Declare @ParamDefinitions nvarchar(1024)
Set @ParamDefinitions = N'@UserId int,NTUser varchar(30), @XmlResult XML OUTPUT'
Set @SqlCmd = N'Set @XmlResult =
(
Select
[UserId] [a],
[UserName] [b],

[code]....

View 7 Replies View Related

Stored Procedure Doesn't Recompile After Replication Updates Underlying Tables

Mar 21, 2007

We have on demand snapshot replication set up between 2 servers. When the subscriber applies the snapshot, our stored procedures start executing very slowly. Updating statistics and rebuilding indexes does not resolve the problem, however; executing sp_recompile on the affected stored procedures does fix the problem. Is this a known issue with replication? Is there a better workaround than manually recompiling stored procedures after every snapshot?

View 3 Replies View Related

SQL Server 2008 :: How To Make Sproc Return Errors For Underlying Table Errors

Jul 1, 2015

I recently updated the datatype of a sproc parameter from bit to tinyint. When I executed the sproc with the updated parameters the sproc appeared to succeed and returned "1 row(s) affected" in the console. However, the update triggered by the sproc did not actually work.

The table column was a bit which only allows 0 or 1 and the sproc was passing a value of 2 so the table was rejecting this value. However, the sproc did not return an error and appeared to return success. So is there a way to configure the database or sproc to return an error message when this type of error occurs?

View 1 Replies View Related

SSIS Warnings On Build 3159: Precompiled Script Failed To Load. Attempting To Recompile.

Aug 20, 2007

All:

I've implemented a variation of the Custom Logging provided in this post by Jamie Thomson.


http://blogs.conchango.com/jamiethomson/archive/2005/06/11/SSIS_3A00_-Custom-Logging-Using-Event-Handlers.aspx

Everything seems to work well on my desktop during development, but when I deployed the packages to our DEV environment the packages still execute, but I'm now receiving warning messages in the sysdtslog90 log table...

Precompiled script failed to load. Attempting to recompile. For more information, see the Microsoft Knowledge Base article, KB931846 (http://go.microsoft.com/fwlink/?LinkId=81885).


My log table (SSISLog) looks OK, with only OnPostExecute messages that include the package / task information and rowcounts.


The KB article suggests upgrading to SP2, but I'm well past SP2, using Build 3159 on both machines.

Any suggestions on how to get rid of the warnings?

Thanks!
Leda


View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved