Showing posts with label trigger. Show all posts
Showing posts with label trigger. Show all posts

Friday, March 9, 2012

Logical Tables in Trigger?

Hi,
What are the Logical Tables in triggers?
Is there anything like that is available?
Please help me in this regard.
Thanks,
Shhyam
WHile you are in a trigger you have access to 2 tables, named inserted and
deleted. They are read-only and have the same structure as the table the
trigger is based on.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Shyam" <Shyam@.discussions.microsoft.com> wrote in message
news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
> Hi,
> What are the Logical Tables in triggers?
> Is there anything like that is available?
> Please help me in this regard.
> Thanks,
> Shhyam
|||Hi Wayne,
I get your point,but it would be helpful for me,if you can provide more
details on this.Any Url/helpfile would be apperciated.
Regards,
shyam
"Wayne Snyder" wrote:

> WHile you are in a trigger you have access to 2 tables, named inserted and
> deleted. They are read-only and have the same structure as the table the
> trigger is based on.
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
>
>
|||Hi Shyam
The best helpfile is SQL Server's own documentation. Look up CREATE TRIGGER
in the Books Online and that should get you started, as there are quite a
few examples under that topic.
HTH
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Shyam" <Shyam@.discussions.microsoft.com> wrote in message
news:D95816D6-2BED-4E95-ADE2-B4AC3E6EF753@.microsoft.com...[vbcol=seagreen]
> Hi Wayne,
> I get your point,but it would be helpful for me,if you can provide more
> details on this.Any Url/helpfile would be apperciated.
> Regards,
> shyam
> "Wayne Snyder" wrote:
|||Thanks all for the quick help.
Regards,
shyam
"Kalen Delaney" wrote:

> Hi Shyam
> The best helpfile is SQL Server's own documentation. Look up CREATE TRIGGER
> in the Books Online and that should get you started, as there are quite a
> few examples under that topic.
> --
> HTH
> --
> Kalen Delaney
> SQL Server MVP
> www.SolidQualityLearning.com
>
> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> news:D95816D6-2BED-4E95-ADE2-B4AC3E6EF753@.microsoft.com...
>
>

Logical Tables in Trigger?

Hi,
What are the Logical Tables in triggers?
Is there anything like that is available?
Please help me in this regard.
Thanks,
ShhyamWHile you are in a trigger you have access to 2 tables, named inserted and
deleted. They are read-only and have the same structure as the table the
trigger is based on.
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Shyam" <Shyam@.discussions.microsoft.com> wrote in message
news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
> Hi,
> What are the Logical Tables in triggers?
> Is there anything like that is available?
> Please help me in this regard.
> Thanks,
> Shhyam|||Hi Wayne,
I get your point,but it would be helpful for me,if you can provide more
details on this.Any Url/helpfile would be apperciated.
Regards,
shyam
"Wayne Snyder" wrote:
> WHile you are in a trigger you have access to 2 tables, named inserted and
> deleted. They are read-only and have the same structure as the table the
> trigger is based on.
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
> > Hi,
> >
> > What are the Logical Tables in triggers?
> > Is there anything like that is available?
> > Please help me in this regard.
> >
> > Thanks,
> > Shhyam
>
>|||Hi Shyam
The best helpfile is SQL Server's own documentation. Look up CREATE TRIGGER
in the Books Online and that should get you started, as there are quite a
few examples under that topic.
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Shyam" <Shyam@.discussions.microsoft.com> wrote in message
news:D95816D6-2BED-4E95-ADE2-B4AC3E6EF753@.microsoft.com...
> Hi Wayne,
> I get your point,but it would be helpful for me,if you can provide more
> details on this.Any Url/helpfile would be apperciated.
> Regards,
> shyam
> "Wayne Snyder" wrote:
>> WHile you are in a trigger you have access to 2 tables, named inserted
>> and
>> deleted. They are read-only and have the same structure as the table the
>> trigger is based on.
>> --
>> Wayne Snyder, MCDBA, SQL Server MVP
>> Mariner, Charlotte, NC
>> www.mariner-usa.com
>> (Please respond only to the newsgroups.)
>> I support the Professional Association of SQL Server (PASS) and it's
>> community of SQL Server professionals.
>> www.sqlpass.org
>> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
>> news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
>> > Hi,
>> >
>> > What are the Logical Tables in triggers?
>> > Is there anything like that is available?
>> > Please help me in this regard.
>> >
>> > Thanks,
>> > Shhyam
>>|||Thanks all for the quick help.
Regards,
shyam
"Kalen Delaney" wrote:
> Hi Shyam
> The best helpfile is SQL Server's own documentation. Look up CREATE TRIGGER
> in the Books Online and that should get you started, as there are quite a
> few examples under that topic.
> --
> HTH
> --
> Kalen Delaney
> SQL Server MVP
> www.SolidQualityLearning.com
>
> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> news:D95816D6-2BED-4E95-ADE2-B4AC3E6EF753@.microsoft.com...
> > Hi Wayne,
> >
> > I get your point,but it would be helpful for me,if you can provide more
> > details on this.Any Url/helpfile would be apperciated.
> > Regards,
> > shyam
> >
> > "Wayne Snyder" wrote:
> >
> >> WHile you are in a trigger you have access to 2 tables, named inserted
> >> and
> >> deleted. They are read-only and have the same structure as the table the
> >> trigger is based on.
> >>
> >> --
> >> Wayne Snyder, MCDBA, SQL Server MVP
> >> Mariner, Charlotte, NC
> >> www.mariner-usa.com
> >> (Please respond only to the newsgroups.)
> >>
> >> I support the Professional Association of SQL Server (PASS) and it's
> >> community of SQL Server professionals.
> >> www.sqlpass.org
> >>
> >> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> >> news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
> >> > Hi,
> >> >
> >> > What are the Logical Tables in triggers?
> >> > Is there anything like that is available?
> >> > Please help me in this regard.
> >> >
> >> > Thanks,
> >> > Shhyam
> >>
> >>
> >>
>
>

Logical Tables in Trigger?

Hi,
What are the Logical Tables in triggers?
Is there anything like that is available?
Please help me in this regard.
Thanks,
ShhyamWHile you are in a trigger you have access to 2 tables, named inserted and
deleted. They are read-only and have the same structure as the table the
trigger is based on.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Shyam" <Shyam@.discussions.microsoft.com> wrote in message
news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
> Hi,
> What are the Logical Tables in triggers?
> Is there anything like that is available?
> Please help me in this regard.
> Thanks,
> Shhyam|||Hi Wayne,
I get your point,but it would be helpful for me,if you can provide more
details on this.Any Url/helpfile would be apperciated.
Regards,
shyam
"Wayne Snyder" wrote:

> WHile you are in a trigger you have access to 2 tables, named inserted and
> deleted. They are read-only and have the same structure as the table the
> trigger is based on.
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> news:9F7FB9AF-6953-426C-9142-3F3BBEC61899@.microsoft.com...
>
>|||Hi Shyam
The best helpfile is SQL Server's own documentation. Look up CREATE TRIGGER
in the Books Online and that should get you started, as there are quite a
few examples under that topic.
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Shyam" <Shyam@.discussions.microsoft.com> wrote in message
news:D95816D6-2BED-4E95-ADE2-B4AC3E6EF753@.microsoft.com...[vbcol=seagreen]
> Hi Wayne,
> I get your point,but it would be helpful for me,if you can provide more
> details on this.Any Url/helpfile would be apperciated.
> Regards,
> shyam
> "Wayne Snyder" wrote:
>|||Thanks all for the quick help.
Regards,
shyam
"Kalen Delaney" wrote:

> Hi Shyam
> The best helpfile is SQL Server's own documentation. Look up CREATE TRIGGE
R
> in the Books Online and that should get you started, as there are quite a
> few examples under that topic.
> --
> HTH
> --
> Kalen Delaney
> SQL Server MVP
> www.SolidQualityLearning.com
>
> "Shyam" <Shyam@.discussions.microsoft.com> wrote in message
> news:D95816D6-2BED-4E95-ADE2-B4AC3E6EF753@.microsoft.com...
>
>

Wednesday, March 7, 2012

logical inserted table and after triggers

for some reason my create trigger query fails because sql server cannot resolve the term inserted. It won't even parse without errors. This is what my t-sql looks like

CREATE TRIGGER UserTypeTrig ON GTData.dbo.GTUserType

AFTER Insert, Update

AS

SET NOCOUNT ON

IF EXISTS(SELECT *

FROM GTData.dbo.GTUserType G

JOIN INSERTED I

ON G.TypeID != I.TypeID AND LOWER(G.UserType) = LOWER(I.UserType);

BEGIN;

RAISERROR('cannot insert duplicate userType', 16, 1)

ROLLBACK TRANSACTION

RETURN

END;

appreciate all the help i can get.

Your syntax is not correct. You are using statement terminators in the wrong place. See the modified code:

CREATE TRIGGER UserTypeTrig ON GTData.dbo.GTUserType

AFTER Insert, Update

AS

SET NOCOUNT ON;

IF EXISTS(SELECT *

FROM GTData.dbo.GTUserType G

JOIN INSERTED I

ON G.TypeID != I.TypeID AND LOWER(G.UserType) = LOWER(I.UserType)

)

BEGIN;

RAISERROR('cannot insert duplicate userType', 16, 1);

ROLLBACK TRANSACTION;

RETURN;

END;

|||

Umachandar Jayachandran

Thanks a lot!

Friday, February 24, 2012

Logging Usage (logins)?

Hi everyone!

Can anyone tell me if it's possible to set up some kind of a trigger that will write out to a file or a table and log details of all database connections?
ie: user, datetime of connection, database connected to, etc.

Any help appreciated.

Cheers,
MeganHi Meagan ,

Use SQL Profiler and run a trace you will then see which user connected to which database and at which time they did so ...and more.

Regards
Burner