want to check, triggers are executed After the command is done right? not b4 isit? so if i want to check if the entry is to be Inserted, i should use SP instead? either that or i can use ROLLBACK right? how do i use ROLLBACK? finding Google also at the moment
Does anyone know of or have a method for tracking stored procedures that get called by a trigger. I have inherited a project that when a user updates a row in a particular table, triggers get fired and result in a nesting error. Thanks for your help in advance.
Can I have a trigger call a stroed procedure and then in turn have the stored procedure call a COM object? If so how? Or where can I get the info to do it?
I have to write a script that would make prefixes for a word
for ex: Ragini Venkataraman ( is the string) is the record from one table and i need to store prefix "rag" and "ven" as two records in another table.... I need to know if this can be done using just SQL stored procedures or triggers...or if there needs to be some code(java code..we are using language java) written.. any help on how it can be done would be great....iam completely new to sql and it all seems confusing....
I would like to know if the the DLL`s one can build with VB5/6 can be used to construct Extended Stored Procedures in MS SQLServer 6.5? If so, how does one do this. All the reference material I`ve come across is for C
I would like to know if the the DLL`s one can build with VB5/6 can be used to construct Extended Stored Procedures in MS SQLServer 6.5? If so, how does one do this. All the reference material I`ve come across is for C
For every trigger and stored procedure I have a try-catch that writes to an error_log table. The problem is the inner error is not preserved, always get: The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.
As seen below - though commented out: I tried commiting any transactions - though I didn't create one. I played with the XACT_STATE though that was 0 My test case was last procedure has 1/0
ALTER Trigger [trg_ActivityLogEntryReportsError] ON [dbo].[ActivityLog] FOR INSERT AS
DECLARE @ActivityLogID int ,@AlertMessageTypeID int ,@comment nvarchar(max) ,@Error_Source nvarchar(max) --- etc. SELECT @ActivityLogID = ActivityLogID ,@AlertMessageTypeID = AlertMessageTypeID ,@Comment = Comment FROM INSERTED BEGIN TRY
if @AlertMessageTypeID = 2 -- activity reported an error begin exec proc_CreateAlertLogEntry_forError @ActivityLogID ,@Comment
update ActivityLog set flgActivityChecked = 1 where @activityLogId = activityLogID end END TRY
BEGIN CATCH select @Error_Source = 'trg_ActivityLogEntryReportsError ' ,@Error_Procedure = ERROR_Procedure() --- etc. INSERT INTO ERROR_LOG ( Error_Source ,Error_Procedure ,Error_Message --- etc. ) VALUES ( @Error_Source ,@Error_Procedure ,@Error_Message ---etc. ,@Error_Comment ) -- if @@TRANCOUNT > 0 --begin --commit --end END CATCH
Step 2)
/* This will be called by a Trigger */ ALTER Procedure [dbo].[proc_CreateAlertLogEntry_forError] (@ActivityLogID int ,@Comment nvarchar(max)) AS
Declare @ProcessScheduleID int ,@ProcessID int --,@comment nvarchar(max) ,@Error_Source nvarchar(max) ---etc BEGIN TRY insert into AlertLog ( AlertMessageTypeID ,comment ,ActivityLogID ) values ( 2 -- error ,@comment ,@ActivityLogID )
select @Error_Source = 'trg_AlertLogEntry_SendsOnInsert ' ,@Error_Procedure = ERROR_Procedure() ,@Error_Message = ERROR_MESSAGE() --- etc. INSERT INTO ERROR_LOG ( Error_Source ,Error_Procedure -- etc.) VALUES ( @Error_Source ,@Error_Procedure ,@Error_Message ---etc.) -- if @@TRANCOUNT > 0 --begin --commit --end END CATCH
STEP 4
ALTER Procedure [dbo].[proc_SendEmail] ( @AlertLogID Int ,@AlertMessageTypeID int ,@Comment nvarchar(max) = '' ,@ActivityLogID int = -1 )
AS
declare @AlertSubject nvarchar(512) ,@AlertBody nvarchar(max) ,@myQuery nvarchar(512) ,@profile_name1 nvarchar(128) ,@return_value int ,@mymailitem int ,@Error_Source nvarchar(max) ---etc. ,@Error_Comment nvarchar(max) ,@Test int /* @return_value int -- not using at this point but 0 is OK 1 is failure @mymailitem int -- not using now could store mailitem_id which is on msdb.dbo.sysmail_mailitems sysmail_mailitems.sent_status could be either 0 new, not sent, 1 sent, 2 failure or 3 retry. */
select top 1 @profile_name1 = [name] from msdb.dbo.sysmail_profile order by profile_id
I would like to use the view of the company data in the following stored procedures
without needing to pass a value into the CompanyID identity column. Is there a way to do this? The following code contains the view, the insert trigger on the view, and the desired stored procedures.
Also, this code is given me problem as well the error message says it cannot convert varchar to int. This code is located in the insert trigger.
INSERT INTO State(StateName) VALUES(@StateName)
Here is the code of the company view, notice the C.CompanyID it is used in the GetCompany stored procedure.
FROM Company AS C INNER JOIN Address AS A ON C.AddressID = A.AddressID INNER JOIN State AS S ON A.StateID = S.StateID INNER JOIN Phone AS P ON C.PhoneID = P.PhoneID
Here is code for the insert trigger on the view
CREATE TRIGGER InsertTriggerOnCustomerView ON ViewOfCompany INSTEAD OF INSERT AS BEGIN
DECLARE @CompanyName VARCHAR(128) DECLARE @AddressID INT DECLARE @Street VARCHAR(256) DECLARE @City VARCHAR(128) DECLARE @StateID INT DECLARE @StateName VARCHAR(128) DECLARE @ZipCode INT DECLARE @Country VARCHAR(128) DECLARE @PhoneID INT DECLARE @PhoneNumber VARCHAR(32) --DECLARE @CompanyID INT
INSERT INTO Address(Street, City, StateID, Country, ZipCode) VALUES(@Street, @City, @StateID, @ZipCode, @Country)
SET @AddressID = SCOPE_IDENTITY()
INSERT INTO Phone(PhoneNumber) VALUES(@PhoneNumber)
SET @PhoneID = SCOPE_IDENTITY()
INSERT INTO Company(CompanyName, AddressID, PhoneID) VALUES(@CompanyName, @AddressID, @PhoneID)
END
The stored procedures are here.
CREATE PROCEDURE GetCompany ( @CompanyID INT ) AS BEGIN SELECT CompanyName,Street, City, StateName, ZipCode, Country, PhoneNumber FROM ViewOfCompany WHERE CompanyID = @CompanyID END GO
CREATE PROCEDURE AddCompany ( @CompanyName VARCHAR(128), @Street VARCHAR(256), @City VARCHAR(128), @StateName VARCHAR(128), @ZipCode VARCHAR(128), @Country VARCHAR(128), @PhoneNumber VARCHAR(32) ) AS BEGIN INSERT INTO ViewOfCompany VALUES(@CompanyName, @Street, @City, @StateName, @ZipCode, @Country, @PhoneNumber) END GO
For those intersted here is our TOC and the book's link. You can preorder at this point. We are sticking to the Nov. timeframe, but we may get it done sooner.
Chapter 1 Introducing SQLCLR Chapter 2 Building a Procedure Chapter 3 SQLCLR Strucutre & Common Tasks Chapter 4 Creating Objects Chapter 5 Compare & Contrast Chapter 6 Replacing TSQL Objects Chapter 7 Using the Base Library Chapter 8 Using Procedures in Apps Chapter 9 Error Handling Chapter 10 Administration Chapter 11 Case Study
If I kick off my C# executable from the server everything works fine but if I have another C# executable kick off the C# executable that runs the SSIS I get an error message saying it cannot run SSIS package. I am thinking it sounds like a permissions problem but not sure. Any suggestions/guidance would be greatly appreciated.
Errors I am getting.
2007-09-26 15:02:30,187 [1] ERROR reporting.Processor [(null)] - Problem with Direct Script
I'm on a application server and i need to run a executable file from a SP, my problem is if i use xp_cmdshell (from the SP) it will try to run it on the SQL Server not on a App server, this a third party executable so cannnot be run on the sql backend.
I need to create a procedure to output mean and deviation AND then I also need to create a trigger. Below is the table 'Account' I made.. but the procedure and trigger I made below that is not correct. Can someone revise this for me? I just can't figure it out.
Now I need to output the Mean and Standard Deviation of the above Account. So I tried this code but I'm not sure if its right since when I Analyze it, some values come out as 'null'.
CREATE PROCEDURE project2question2 AS
DECLARE @Mean MONEY
DECLARE @Deviation MONEY
SET @Mean = (SELECT avg(cast(Balance as float)) as mean from Account)
SET @Deviation = (SELECT Balance, STDEV(Balance) st_deviation
The second question was to create a Trigger that would output the name "Account" and the time of change/update to it. So I had this so far, but I KNOW its not right, so can anyone revise this for me? I basically need to create a trigger named ActionHistory that would have two columns: TableName and ActionTime. They should tie to my Account table so that when it was changed/updated then the name 'Account' would appear under TableName in my trigger, and the datetime of update would appear under ActionTime. But I just can't figure this one out.
Create table ActionHistory(TableName varchar(12) NOT NULL, ActionTime datetime NOT NULL)
CREATE TRIGGER trigger_ex2
ON ActionHistory
AFTER INSERT, UPDATE
AS
BEGIN
UPDATE ActionHistory
SET Account = UPPER(LName) WHERE TableName in (SELECT TableName FROM ActionHistory)
SET Loan = UPPER(LName) WHERE IDN in (SELECT TableName FROM ActionHistory)
I want to know the differences between SQL Server 2000 storedprocedures and oracle stored procedures? Do they have differentsyntax? The concept should be the same that the stored proceduresexecute in the database server with better performance?Please advise good references for Oracle stored procedures also.thanks!!
This Might be a really simple thing, however we have just installed SQL server 2005 on a new server, and are having difficulties with the set up of the Store Procedures. Every time we try to modify an existing stored procedure it attempts to save it as an SQL file, unlike in 2000 where it saved it as part of the database itself.
Using SQL 2005, SP2. All of a sudden, whenever I create any stored procedures in the master database, they get created as system stored procedures. Doesn't matter what I name them, and what they do.
For example, even this simple little guy:
CREATE PROCEDURE BOB
AS
PRINT 'BOB'
GO
Gets created as a system stored procedure.
Any ideas what would cause that and/or how to fix it?
I didn't want to maintain similar/identical tables in a legacy FoxPro system and another system with SQL Server back end. Both systems are active, but some tables are shared.
Initially I was going to use a Linked Server to the FoxPro to pull the FP data when needed. This works. But, I've come up with what I believe is a better solution. Keep in mind that these tables are largely static - occassional changes, edits.
I will do a 1 time DTS from FP into SQL Server tables.
I then create INSERT and UPDATE triggers within FoxPro.
These triggers fire a stored procedure in FoxPro that establishes a connection to the SQL Server and fire the appropriate stored procedure on SQL Server to CREATE and/or UPDATE the corresponding table there.
In the end - the tables are local to both apps.
If the UPDATES or TRIGGERS fail I write to an error log - and in that rare case - I can manually fix. I could set it up to email me from within FoxPro as well if needed.
Here's the FoxPro and SQL Server code for reference for the Record Insert:
How do I search for and print all stored procedure names in a particular database? I can use the following query to search and print out all table names in a database. I just need to figure out how to modify the code below to search for stored procedure names. Can anyone help me out? SELECT TABLE_SCHEMA + '.' + TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'
Seems like I'm stealing all the threads here, : But I need to learn :) I have a StoredProcedure that needs to return values that other StoredProcedures return.Rather than have my DataAccess layer access the DB multiple times, I would like to call One stored Procedure, and have that stored procedure call the others to get the information I need. I think this way would be more efficient than accessing the DB multiple times. One of my SP is:SELECT I.ItemDetailID, I.ItemDetailStatusID, I.ItemDetailTypeID, I.Archived, I.Expired, I.ExpireDate, I.Deleted, S.Name AS 'StatusName', S.ItemDetailStatusID, S.InProgress as 'StatusInProgress', S.Color AS 'StatusColor',T.[Name] AS 'TypeName', T.Prefix, T.Name AS 'ItemDetailTypeName', T.ItemDetailTypeID FROM [Item].ItemDetails I INNER JOIN Item.ItemDetailStatus S ON I.ItemDetailStatusID = S.ItemDetailStatusID INNER JOIN [Item].ItemDetailTypes T ON I.ItemDetailTypeID = T.ItemDetailTypeID However, I already have StoredProcedures that return the exact same data from the ItemDetailStatus table and ItemDetailTypes table.Would it be better to do it above, and have more code to change when a new column/field is added, or more checks, or do something like:(This is not propper SQL) SELECT I.ItemDetailID, I.ItemDetailStatusID, I.ItemDetailTypeID, I.Archived, I.Expired, I.ExpireDate, I.Deleted, EXEC [Item].ItemDetailStatusInfo I.ItemDetailStatusID, EXEC [Item].ItemDetailTypeInfo I.ItemDetailTypeID FROM [Item].ItemDetails IOr something like that... Any thoughts?
I have MSSQL 2005. On earlier versions of MSSQL saving a stored procedure wasn't a confusing action. However, every time I try to save my completed stored procedure (parsed successfully ) I'm prompted to save it as a query on the hard drive.
How do I cause the 'Save' action to add the new stored procedure to my database's list of stored procedures?
We recently upgraded to SQL Server 2005. We had several stored procedures in the master database and, rather than completely rewriting a lot of code, we just recreated these stored procedures in the new master database.
For some reason, some of these stored procedures are getting stored as "System Stored Procedures" rather than just as "Stored Procedures". Queries to sys.Objects and sys.Procedures shows that these procs are being saved with the is_ms_shipped field set to 1, even though they obviously were not shipped with the product.
I can't update the sys.Objects or sys.Procedures views in 2005.
What effect will this flag (is_ms_shipped = 1) have on my stored procedures?
Can I move these out of "System Stored Procedures" and into "Stored Procedures"?
I'm trying to initiate an executable from a job step. This executable functions normally from a command prompt on the server and will initiate properly from a DTS package that is executed locally by a logged in user. It won't run from Query Analyzer, an Operating System Command jobstep, or a scheduled DTS package. The executable creates a report that gets written to disk and a window shows briefly during execution.
MS SQL 2000 on Win2K.
Any clues as to how to run this executable from a scheduled jobstep?
We have a job set up that runs a Visual Basic executable file. It was running fine. We just upgraded to SQL2000. The job still seems to run ok, but we are getting a message that the job failed. "The step did not generate any output. Process Exit Code -1073741819. The step failed." Yet, when we check the output tables, it seems as though the job ran ok. The programmer is not passing any exit codes. Any ideas?
Hi, I'm new to SQL and I just got a new job with very little hands on training. I have executed a CreateTables.sql and now my boss wants me to run a Conversion.exe file. I am not sure how to do that, any help would be most appreciated. Thanks, Laura