How can I force the contents of Query Analyzer's buffer to display to the
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> > How can I force the contents of Query Analyzer's buffer to display to
the
> > screen?
> >
> > A stored proc has some debug PRINT statements in it. The proc takes a
> long
> > time to execute and the PRINT statements don't display until execution
is
> > complete.
> >
> > Is it possible to force them to display immediately? If so, how?
> >
> >
>|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
--
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> > How can I force the contents of Query Analyzer's buffer to display to
the
> > screen?
> >
> > A stored proc has some debug PRINT statements in it. The proc takes a
> long
> > time to execute and the PRINT statements don't display until execution
is
> > complete.
> >
> > Is it possible to force them to display immediately? If so, how?
> >
> >
>|||Good point, just in the habit of using 11.
--
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> > How about RAISERROR WITH NOWAIT? Watch the messages pane:
> >
> >
> > PRINT 'foo'
> > WAITFOR DELAY '00:00:05'
> > GO
> > RAISERROR('foo', 11, 1) WITH NOWAIT
> > WAITFOR DELAY '00:00:05'
> > GO
> >
> >
> > --
> > http://www.aspfaq.com/
> > (Reverse address to reply.)
> >
> >
> >
> >
> > "Dave" <dave@.nospam.ru> wrote in message
> > news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> > > How can I force the contents of Query Analyzer's buffer to display to
> the
> > > screen?
> > >
> > > A stored proc has some debug PRINT statements in it. The proc takes a
> > long
> > > time to execute and the PRINT statements don't display until execution
> is
> > > complete.
> > >
> > > Is it possible to force them to display immediately? If so, how?
> > >
> > >
> >
> >
>|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
>> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>>
>> PRINT 'foo'
>> WAITFOR DELAY '00:00:05'
>> GO
>> RAISERROR('foo', 11, 1) WITH NOWAIT
>> WAITFOR DELAY '00:00:05'
>> GO
>>
>> --
>> http://www.aspfaq.com/
>> (Reverse address to reply.)
>>
>>
>> "Dave" <dave@.nospam.ru> wrote in message
>> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
>> > How can I force the contents of Query Analyzer's buffer to display to
> the
>> > screen?
>> >
>> > A stored proc has some debug PRINT statements in it. The proc takes a
>> long
>> > time to execute and the PRINT statements don't display until execution
> is
>> > complete.
>> >
>> > Is it possible to force them to display immediately? If so, how?
>> >
>> >
>>
>|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> > THe red error messages are a distraction but I can live with that.
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> > Thanks Aaron
> >
> > That works and it also prints out any unprinted PRINT statements
previous to
> > the RAISERROR.
> >
> > THe red error messages are a distraction but I can live with that.
> >
> > Thank you.
> >
> >
> > "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> > news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> >> How about RAISERROR WITH NOWAIT? Watch the messages pane:
> >>
> >>
> >> PRINT 'foo'
> >> WAITFOR DELAY '00:00:05'
> >> GO
> >> RAISERROR('foo', 11, 1) WITH NOWAIT
> >> WAITFOR DELAY '00:00:05'
> >> GO
> >>
> >>
> >> --
> >> http://www.aspfaq.com/
> >> (Reverse address to reply.)
> >>
> >>
> >>
> >>
> >> "Dave" <dave@.nospam.ru> wrote in message
> >> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> >> > How can I force the contents of Query Analyzer's buffer to display to
> > the
> >> > screen?
> >> >
> >> > A stored proc has some debug PRINT statements in it. The proc takes
a
> >> long
> >> > time to execute and the PRINT statements don't display until
execution
> > is
> >> > complete.
> >> >
> >> > Is it possible to force them to display immediately? If so, how?
> >> >
> >> >
> >>
> >>
> >
> >
>|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?|||SQL Server doesn't send its output to the client immediately as it is generated by the engine. This
is to consume less network resources. And this is the reason why we don't see things like PRINT
immediately after they have been performed. SQL Server will wait until its output buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
the output buffer.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:
>> How can I force the contents of Query Analyzer's buffer to display to the
>> screen?
>> A stored proc has some debug PRINT statements in it. The proc takes a long
>> time to execute and the PRINT statements don't display until execution is
>> complete.
>> Is it possible to force them to display immediately? If so, how?|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
--
http://www.aspfaq.com/
(Reverse address to reply.)
Showing posts with label statements. Show all posts
Showing posts with label statements. Show all posts
Monday, March 26, 2012
Forcing display of QA's buffer
How can I force the contents of Query Analyzer's buffer to display to the
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?
How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>
|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is
>
|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is
>
|||Good point, just in the habit of using 11.
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>
|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>
|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...[vbcol=seagreen]
previous to[vbcol=seagreen]
a[vbcol=seagreen]
execution
>
|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
|||SQL Server doesn't send its output to the client immediately as it is generated by the engine. This
is to consume less network resources. And this is the reason why we don't see things like PRINT
immediately after they have been performed. SQL Server will wait until its output buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
the output buffer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...[vbcol=seagreen]
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:
|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
http://www.aspfaq.com/
(Reverse address to reply.)
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?
How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>
|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is
>
|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...[vbcol=seagreen]
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is
>
|||Good point, just in the habit of using 11.
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>
|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>
|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...[vbcol=seagreen]
previous to[vbcol=seagreen]
a[vbcol=seagreen]
execution
>
|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
|||SQL Server doesn't send its output to the client immediately as it is generated by the engine. This
is to consume less network resources. And this is the reason why we don't see things like PRINT
immediately after they have been performed. SQL Server will wait until its output buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
the output buffer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...[vbcol=seagreen]
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:
|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
http://www.aspfaq.com/
(Reverse address to reply.)
Friday, March 23, 2012
Forcing display of QA's buffer
How can I force the contents of Query Analyzer's buffer to display to the
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is[vbcol=seagreen]
>|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is[vbcol=seagreen]
>|||Good point, just in the habit of using 11.
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...[vbcol
=seagreen]
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous
to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>[/vbcol]|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
previous to[vbcol=seagreen]
a[vbcol=seagreen]
execution[vbcol=seagreen]
>|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a lon
g
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?|||SQL Server doesn't send its output to the client immediately as it is genera
ted by the engine. This
is to consume less network resources. And this is the reason why we don't se
e things like PRINT
immediately after they have been performed. SQL Server will wait until its o
utput buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it fo
rces SQL Server to flush
the output buffer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...[vbcol=s
eagreen]
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
http://www.aspfaq.com/
(Reverse address to reply.)sql
screen?
A stored proc has some debug PRINT statements in it. The proc takes a long
time to execute and the PRINT statements don't display until execution is
complete.
Is it possible to force them to display immediately? If so, how?How about RAISERROR WITH NOWAIT? Watch the messages pane:
PRINT 'foo'
WAITFOR DELAY '00:00:05'
GO
RAISERROR('foo', 11, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO
http://www.aspfaq.com/
(Reverse address to reply.)
"Dave" <dave@.nospam.ru> wrote in message
news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a
long
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?
>|||Even better, use a severity of 10 or lower to emulate what PRINT does (i.e.,
no error condition raised)...
Adam Machanic
SQL Server MVP
http://www.sqljunkies.com/weblog/amachanic
--
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is[vbcol=seagreen]
>|||Thanks Aaron
That works and it also prints out any unprinted PRINT statements previous to
the RAISERROR.
THe red error messages are a distraction but I can live with that.
Thank you.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> How about RAISERROR WITH NOWAIT? Watch the messages pane:
>
> PRINT 'foo'
> WAITFOR DELAY '00:00:05'
> GO
> RAISERROR('foo', 11, 1) WITH NOWAIT
> WAITFOR DELAY '00:00:05'
> GO
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
> "Dave" <dave@.nospam.ru> wrote in message
> news:uyWPdkbHFHA.2784@.TK2MSFTNGP09.phx.gbl...
the[vbcol=seagreen]
> long
is[vbcol=seagreen]
>|||Good point, just in the habit of using 11.
http://www.aspfaq.com/
(Reverse address to reply.)
"Adam Machanic" <amachanic@.hotmail._removetoemail_.com> wrote in message
news:egrs6xbHFHA.720@.TK2MSFTNGP10.phx.gbl...
> Even better, use a severity of 10 or lower to emulate what PRINT does
(i.e.,
> no error condition raised)...
> --
> Adam Machanic
> SQL Server MVP
> http://www.sqljunkies.com/weblog/amachanic
> --
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>|||> THe red error messages are a distraction but I can live with that.
Just follow Adam's advice and lower the severity level.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Dave" <dave@.nospam.ru> wrote in message news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...[vbcol
=seagreen]
> Thanks Aaron
> That works and it also prints out any unprinted PRINT statements previous
to
> the RAISERROR.
> THe red error messages are a distraction but I can live with that.
> Thank you.
>
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:uVVzjnbHFHA.4048@.TK2MSFTNGP15.phx.gbl...
> the
> is
>[/vbcol]|||Got it.
Thanks
"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uj4f94bHFHA.3624@.tk2msftngp13.phx.gbl...
> Just follow Adam's advice and lower the severity level.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "Dave" <dave@.nospam.ru> wrote in message
news:emHu5xbHFHA.3780@.TK2MSFTNGP10.phx.gbl...
previous to[vbcol=seagreen]
a[vbcol=seagreen]
execution[vbcol=seagreen]
>|||did you try using "results in text" instead of "results in grid"?
Dave wrote:
> How can I force the contents of Query Analyzer's buffer to display to the
> screen?
> A stored proc has some debug PRINT statements in it. The proc takes a lon
g
> time to execute and the PRINT statements don't display until execution is
> complete.
> Is it possible to force them to display immediately? If so, how?|||SQL Server doesn't send its output to the client immediately as it is genera
ted by the engine. This
is to consume less network resources. And this is the reason why we don't se
e things like PRINT
immediately after they have been performed. SQL Server will wait until its o
utput buffer is full, or
until the batch has ended. The trick with RAISERROR and NOWAIT is that it fo
rces SQL Server to flush
the output buffer.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ch" <ch@.dontemailme.com> wrote in message news:42237E8F.7DC18B52@.dontemailme.com...[vbcol=s
eagreen]
> did you try using "results in text" instead of "results in grid"?
>
> Dave wrote:|||> The trick with RAISERROR and NOWAIT is that it forces SQL Server to flush
> the output buffer.
Right, this is why you usually see the PRINT and the RAISERROR come to the
messages pane at roughly the same time, even if the PRINT is issued before a
delay and the RAISERROR comes after.
http://www.aspfaq.com/
(Reverse address to reply.)sql
Friday, February 24, 2012
FOR loop
Why does'nt SQL Server 2000 support For loop conditional statements? I know
While and IF's are there, but what made Microsfot not include a For loop?use the while loop
"Srikant" <Srikant@.discussions.microsoft.com> wrote in message
news:A6D2ED63-2AB9-48FC-AF10-E151AC1707FB@.microsoft.com...
> Why does'nt SQL Server 2000 support For loop conditional statements? I
> know
> While and IF's are there, but what made Microsfot not include a For loop?|||Why does one language have this construct and the other language have anothe
r construct? As you can
imagine, we can't answer that question, because we haven't been present at t
he language design
meetings that Sybase and Microsoft has had over the years. They probably inc
luded WHILE first (every
product has a first release) and there haven't been enough customer demand t
o add further language
elements...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Srikant" <Srikant@.discussions.microsoft.com> wrote in message
news:A6D2ED63-2AB9-48FC-AF10-E151AC1707FB@.microsoft.com...
> Why does'nt SQL Server 2000 support For loop conditional statements? I kno
w
> While and IF's are there, but what made Microsfot not include a For loop?|||SQL server is not a programming language.
You're lucky to have While.
I don't think that I've ever used While in SQL.
CELKO would be proud.
"Srikant" <Srikant@.discussions.microsoft.com> wrote in message
news:A6D2ED63-2AB9-48FC-AF10-E151AC1707FB@.microsoft.com...
> Why does'nt SQL Server 2000 support For loop conditional statements? I
> know
> While and IF's are there, but what made Microsfot not include a For loop?|||Why do you want a FOR loop? Maybe there is a better way to do it in
TSQL. Or perhaps you are using TSQL for something it was never intended
for.
David Portas
SQL Server MVP
--|||WHILE and FOR loops are the same in languages like C:
for (int i=0; i < 5; ++i);
is identical (except for scope of "i") to:
int i = 0;
while (i < 5) i += 1;
"Srikant" wrote:
> Why does'nt SQL Server 2000 support For loop conditional statements? I kno
w
> While and IF's are there, but what made Microsfot not include a For loop?|||You can say anything to an officer as long as you precede it and end it with
'Sir'.
So you can use any garbage you want so long as you precede it with 'SELECT'.
Hmm...something about false idols?:)
"Raymond D'Anjou" <rdanjou@.savantsoftNOSPAM.net> wrote in message
news:%23jjVJnRRFHA.252@.TK2MSFTNGP12.phx.gbl...
> SQL server is not a programming language.
> You're lucky to have While.
> I don't think that I've ever used While in SQL.
> CELKO would be proud.|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uyDp5iRRFHA.3944@.TK2MSFTNGP10.phx.gbl...
..
> They probably included WHILE first (every product has a first release) and
> there haven't been enough customer demand to add further language
> elements...
Where can I find this data? :)
While and IF's are there, but what made Microsfot not include a For loop?use the while loop
"Srikant" <Srikant@.discussions.microsoft.com> wrote in message
news:A6D2ED63-2AB9-48FC-AF10-E151AC1707FB@.microsoft.com...
> Why does'nt SQL Server 2000 support For loop conditional statements? I
> know
> While and IF's are there, but what made Microsfot not include a For loop?|||Why does one language have this construct and the other language have anothe
r construct? As you can
imagine, we can't answer that question, because we haven't been present at t
he language design
meetings that Sybase and Microsoft has had over the years. They probably inc
luded WHILE first (every
product has a first release) and there haven't been enough customer demand t
o add further language
elements...
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Srikant" <Srikant@.discussions.microsoft.com> wrote in message
news:A6D2ED63-2AB9-48FC-AF10-E151AC1707FB@.microsoft.com...
> Why does'nt SQL Server 2000 support For loop conditional statements? I kno
w
> While and IF's are there, but what made Microsfot not include a For loop?|||SQL server is not a programming language.
You're lucky to have While.
I don't think that I've ever used While in SQL.
CELKO would be proud.
"Srikant" <Srikant@.discussions.microsoft.com> wrote in message
news:A6D2ED63-2AB9-48FC-AF10-E151AC1707FB@.microsoft.com...
> Why does'nt SQL Server 2000 support For loop conditional statements? I
> know
> While and IF's are there, but what made Microsfot not include a For loop?|||Why do you want a FOR loop? Maybe there is a better way to do it in
TSQL. Or perhaps you are using TSQL for something it was never intended
for.
David Portas
SQL Server MVP
--|||WHILE and FOR loops are the same in languages like C:
for (int i=0; i < 5; ++i);
is identical (except for scope of "i") to:
int i = 0;
while (i < 5) i += 1;
"Srikant" wrote:
> Why does'nt SQL Server 2000 support For loop conditional statements? I kno
w
> While and IF's are there, but what made Microsfot not include a For loop?|||You can say anything to an officer as long as you precede it and end it with
'Sir'.
So you can use any garbage you want so long as you precede it with 'SELECT'.
Hmm...something about false idols?:)
"Raymond D'Anjou" <rdanjou@.savantsoftNOSPAM.net> wrote in message
news:%23jjVJnRRFHA.252@.TK2MSFTNGP12.phx.gbl...
> SQL server is not a programming language.
> You're lucky to have While.
> I don't think that I've ever used While in SQL.
> CELKO would be proud.|||"Tibor Karaszi" <tibor_please.no.email_karaszi@.hotmail.nomail.com> wrote in
message news:uyDp5iRRFHA.3944@.TK2MSFTNGP10.phx.gbl...
..
> They probably included WHILE first (every product has a first release) and
> there haven't been enough customer demand to add further language
> elements...
Where can I find this data? :)
For Insert/After Insert -- Default Trigger Question
Hello,
I am a little
between For Insert and After Insert statements on
Triggers. I just need to know which is the Sql Server Default Trigger. Her
e
are 2 sample Triggers. Is For Insert or After Insert the default?
---
CREATE TRIGGER my_trig
ON my_table
FOR INSERT
AS
IF UPDATE(b)
PRINT 'Column b Modified'
GO
---
Create Trigger Update_Status
On ACRPLU AFTER INSERT
As
Update A Set A.a1updt = 'D'
From ACRPLU A
Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
In(Select Distinct PK From Inserted)
---
Thanks.
RichRich,
From BOL:
AFTER is the default, if FOR is the only keyword specified.
HTH
Jerry
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:6A02BEF5-E7A3-44DF-B6B3-6C26E336A319@.microsoft.com...
> Hello,
> I am a little
between For Insert and After Insert statements on
> Triggers. I just need to know which is the Sql Server Default Trigger.
> Here
> are 2 sample Triggers. Is For Insert or After Insert the default?
> ---
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> AS
> IF UPDATE(b)
> PRINT 'Column b Modified'
> GO
> ---
> Create Trigger Update_Status
> On ACRPLU AFTER INSERT
> As
> Update A Set A.a1updt = 'D'
> From ACRPLU A
> Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
> In(Select Distinct PK From Inserted)
> ---
> Thanks.
> Rich
>|||AFTER is the default. In other words "AFTER INSERT" means the same as "FOR
INSERT".
David Portas
SQL Server MVP
--
"Rich" wrote:
> Hello,
> I am a little
between For Insert and After Insert statements on
> Triggers. I just need to know which is the Sql Server Default Trigger. H
ere
> are 2 sample Triggers. Is For Insert or After Insert the default?
> ---
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> AS
> IF UPDATE(b)
> PRINT 'Column b Modified'
> GO
> ---
> Create Trigger Update_Status
> On ACRPLU AFTER INSERT
> As
> Update A Set A.a1updt = 'D'
> From ACRPLU A
> Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
> In(Select Distinct PK From Inserted)
> ---
> Thanks.
> Rich
>|||Thanks all for your replies. If I understand the explanations correctly,
what I am interpreting is that
CREATE TRIGGER my_trig
ON my_table
FOR INSERT
...
is the same as
CREATE TRIGGER my_trig
ON my_table
After INSERT
...
Is this correct? This is where my confusion lies.
Thanks,
Rich|||Yes.
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:E21BD983-4695-4D7C-A9EE-854749B1D70B@.microsoft.com...
> Thanks all for your replies. If I understand the explanations correctly,
> what I am interpreting is that
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> ...
> is the same as
> CREATE TRIGGER my_trig
> ON my_table
> After INSERT
> ...
> Is this correct? This is where my confusion lies.
> Thanks,
> Rich|||Thanks. But to take this one step further, since For and After seem to be
the same, is it possible to do this?
CREATE TRIGGER my_trig
ON my_table INSERT
...
where I don't include a For or After? Is this what is meant by default
trigger?
"Jerry Spivey" wrote:
> Yes.
> "Rich" <Rich@.discussions.microsoft.com> wrote in message
> news:E21BD983-4695-4D7C-A9EE-854749B1D70B@.microsoft.com...
>
>|||No.
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:11EBA02F-433D-410A-ABAD-34CAB173E453@.microsoft.com...
> Thanks. But to take this one step further, since For and After seem to be
> the same, is it possible to do this?
> CREATE TRIGGER my_trig
> ON my_table INSERT
> ...
> where I don't include a For or After? Is this what is meant by default
> trigger?
>
> "Jerry Spivey" wrote:
>|||Yes; in earlier versions of SQL Server we only had one kind of trigger, so
we didn't need to say instead of or after. We had a trigger FOR an
operation, and it always fired AFTER the operation took place.
When INSTEAD OF triggers were added, we needed a way to make sure we
differentiated the two kinds of triggers, so AFTER was introduced as a
synonym for FOR.
So really, there is no default. You have to specify when the trigger fires,
either with FOR or AFTER (which are the same) or INSTEAD OF.
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:E21BD983-4695-4D7C-A9EE-854749B1D70B@.microsoft.com...
> Thanks all for your replies. If I understand the explanations correctly,
> what I am interpreting is that
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> ...
> is the same as
> CREATE TRIGGER my_trig
> ON my_table
> After INSERT
> ...
> Is this correct? This is where my confusion lies.
> Thanks,
> Rich
>|||Thanks everyone, again for all the explanations. So if I am not using an
Instead Of trigger, then I can write
Create Trigger...For Update...For Insert...For Delete
or
Create Trigger...After Update...After Insert...After Delete
And it is the same thing. I think I get it now.
Many thanks for all the help.
Rich
"Rich" wrote:
> Hello,
> I am a little
between For Insert and After Insert statements on
> Triggers. I just need to know which is the Sql Server Default Trigger. H
ere
> are 2 sample Triggers. Is For Insert or After Insert the default?
> ---
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> AS
> IF UPDATE(b)
> PRINT 'Column b Modified'
> GO
> ---
> Create Trigger Update_Status
> On ACRPLU AFTER INSERT
> As
> Update A Set A.a1updt = 'D'
> From ACRPLU A
> Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
> In(Select Distinct PK From Inserted)
> ---
> Thanks.
> Rich
>
I am a little
Triggers. I just need to know which is the Sql Server Default Trigger. Her
e
are 2 sample Triggers. Is For Insert or After Insert the default?
---
CREATE TRIGGER my_trig
ON my_table
FOR INSERT
AS
IF UPDATE(b)
PRINT 'Column b Modified'
GO
---
Create Trigger Update_Status
On ACRPLU AFTER INSERT
As
Update A Set A.a1updt = 'D'
From ACRPLU A
Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
In(Select Distinct PK From Inserted)
---
Thanks.
RichRich,
From BOL:
AFTER is the default, if FOR is the only keyword specified.
HTH
Jerry
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:6A02BEF5-E7A3-44DF-B6B3-6C26E336A319@.microsoft.com...
> Hello,
> I am a little
> Triggers. I just need to know which is the Sql Server Default Trigger.
> Here
> are 2 sample Triggers. Is For Insert or After Insert the default?
> ---
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> AS
> IF UPDATE(b)
> PRINT 'Column b Modified'
> GO
> ---
> Create Trigger Update_Status
> On ACRPLU AFTER INSERT
> As
> Update A Set A.a1updt = 'D'
> From ACRPLU A
> Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
> In(Select Distinct PK From Inserted)
> ---
> Thanks.
> Rich
>|||AFTER is the default. In other words "AFTER INSERT" means the same as "FOR
INSERT".
David Portas
SQL Server MVP
--
"Rich" wrote:
> Hello,
> I am a little
> Triggers. I just need to know which is the Sql Server Default Trigger. H
ere
> are 2 sample Triggers. Is For Insert or After Insert the default?
> ---
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> AS
> IF UPDATE(b)
> PRINT 'Column b Modified'
> GO
> ---
> Create Trigger Update_Status
> On ACRPLU AFTER INSERT
> As
> Update A Set A.a1updt = 'D'
> From ACRPLU A
> Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
> In(Select Distinct PK From Inserted)
> ---
> Thanks.
> Rich
>|||Thanks all for your replies. If I understand the explanations correctly,
what I am interpreting is that
CREATE TRIGGER my_trig
ON my_table
FOR INSERT
...
is the same as
CREATE TRIGGER my_trig
ON my_table
After INSERT
...
Is this correct? This is where my confusion lies.
Thanks,
Rich|||Yes.
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:E21BD983-4695-4D7C-A9EE-854749B1D70B@.microsoft.com...
> Thanks all for your replies. If I understand the explanations correctly,
> what I am interpreting is that
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> ...
> is the same as
> CREATE TRIGGER my_trig
> ON my_table
> After INSERT
> ...
> Is this correct? This is where my confusion lies.
> Thanks,
> Rich|||Thanks. But to take this one step further, since For and After seem to be
the same, is it possible to do this?
CREATE TRIGGER my_trig
ON my_table INSERT
...
where I don't include a For or After? Is this what is meant by default
trigger?
"Jerry Spivey" wrote:
> Yes.
> "Rich" <Rich@.discussions.microsoft.com> wrote in message
> news:E21BD983-4695-4D7C-A9EE-854749B1D70B@.microsoft.com...
>
>|||No.
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:11EBA02F-433D-410A-ABAD-34CAB173E453@.microsoft.com...
> Thanks. But to take this one step further, since For and After seem to be
> the same, is it possible to do this?
> CREATE TRIGGER my_trig
> ON my_table INSERT
> ...
> where I don't include a For or After? Is this what is meant by default
> trigger?
>
> "Jerry Spivey" wrote:
>|||Yes; in earlier versions of SQL Server we only had one kind of trigger, so
we didn't need to say instead of or after. We had a trigger FOR an
operation, and it always fired AFTER the operation took place.
When INSTEAD OF triggers were added, we needed a way to make sure we
differentiated the two kinds of triggers, so AFTER was introduced as a
synonym for FOR.
So really, there is no default. You have to specify when the trigger fires,
either with FOR or AFTER (which are the same) or INSTEAD OF.
--
HTH
Kalen Delaney, SQL Server MVP
www.solidqualitylearning.com
"Rich" <Rich@.discussions.microsoft.com> wrote in message
news:E21BD983-4695-4D7C-A9EE-854749B1D70B@.microsoft.com...
> Thanks all for your replies. If I understand the explanations correctly,
> what I am interpreting is that
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> ...
> is the same as
> CREATE TRIGGER my_trig
> ON my_table
> After INSERT
> ...
> Is this correct? This is where my confusion lies.
> Thanks,
> Rich
>|||Thanks everyone, again for all the explanations. So if I am not using an
Instead Of trigger, then I can write
Create Trigger...For Update...For Insert...For Delete
or
Create Trigger...After Update...After Insert...After Delete
And it is the same thing. I think I get it now.
Many thanks for all the help.
Rich
"Rich" wrote:
> Hello,
> I am a little
> Triggers. I just need to know which is the Sql Server Default Trigger. H
ere
> are 2 sample Triggers. Is For Insert or After Insert the default?
> ---
> CREATE TRIGGER my_trig
> ON my_table
> FOR INSERT
> AS
> IF UPDATE(b)
> PRINT 'Column b Modified'
> GO
> ---
> Create Trigger Update_Status
> On ACRPLU AFTER INSERT
> As
> Update A Set A.a1updt = 'D'
> From ACRPLU A
> Where (A.a1updt = '' Or IsNull(A.a1updt, -1) < 0) And A.PK
> In(Select Distinct PK From Inserted)
> ---
> Thanks.
> Rich
>
Subscribe to:
Posts (Atom)