Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Query Analyzer, Tiggers and Print Function

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-02-18 : 09:30:01
Bryan writes "Hi,
The print function seems to not work when running a trigger in the query analyzer. Do you know of any good ways to keep track of the values of a trigger in the query analyzer or any good articles about doing so.
Thanks,
Bryan"

Nazim
A custom title

1408 Posts

Posted - 2002-02-18 : 09:54:29
Have a look at Sql Profiler when the trigger gets executed alternatively you can use Select @varname too.



--------------------------------------------------------------
"Happiness is not something you experience, it's something you remember."

Edited by - Nazim on 02/18/2002 10:06:45
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-02-18 : 10:38:21
Nazim is right, Profiler is better. Triggers should NEVER produce output or results; no Print statements or SELECT statements should appear in a trigger.

Go to Top of Page

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-02-18 : 15:53:23
quote:
no Print statements or SELECT statements should appear in a trigger.



This is a technicality, but for the edification of new folks, Rob is talking about a SELECT statement that returns results for viewing. A SELECT statement as part of an INSERT INTO ... SELECT or a SELECT INTO... are okay because the results get put somewhere other than the display.

------------------------
GENERAL-ly speaking...
Go to Top of Page

byrmol
Shed Building SQL Farmer

1591 Posts

Posted - 2002-02-18 : 16:51:54
Why should there never be a SELECT in a Trigger?

DavidM

Tomorrow is the same day as Today was the day before.
Go to Top of Page

nizmaylo
Constraint Violating Yak Guru

258 Posts

Posted - 2002-02-18 : 17:28:27
You can put print into a body of a trigger for debugging purposes (don't forget to comment it after you're done).

Here is an example

CREATE TRIGGER trig_test1 ON testRating
FOR INSERT, DELETE, UPDATE
AS
IF (EXISTS(SELECT 1 FROM inserted))
AND (NOT EXISTS(SELECT 1 FROM deleted))
PRINT 'insert'
ELSE IF (EXISTS (SELECT 1 FROM inserted))
AND (EXISTS(SELECT 1 FROM deleted))
PRINT 'update'

In order to view the print statement, ask for the results of the query to be shown in text, not grid.

helena
Go to Top of Page
   

- Advertisement -