Drop Table

Support Forum for database administrators and web based access to important newsgroups related to databases
Register on Database Support Forum Edit your profileCalendarFind other Database Support forum membersFrequently Asked QuestionsSearch this forum -> 
For Database admins: Free Database-related Magazines Now Free shipping to Texas


Post New Thread










Thread
Author

Trigger or SP
Hi,
I have a situation in which a  record in inserted into a table say
table1 when any record is inserted in any table in the whole
application. Is it better to use trigger or to write the insert query
in the SP for every table itself.


Report this thread to moderator Post Follow-up to this message
Old Post
Adarsh
03-01-06 01:23 AM


Re: Trigger or SP
I'm not sure inderstood you. What is the purpose?

CREATE TRIGGER TR__Update_MyTable
ON MyTable FOR UPDATE
AS
UPDATE MyTable
SET UpdatedBy = SUSER_SNAME(),
LastUpdatedOn = GETDATE()
WHERE EXISTS
(
SELECT *
FROM inserted
WHERE inserted.PK = MyTable.PK
)



"Adarsh" <shahadarsh@gmail.com> wrote in message
news:1141031175.213071.75040@i40g2000cwc.googlegroups.com...
> Hi,
>     I have a situation in which a  record in inserted into a table say
> table1 when any record is inserted in any table in the whole
> application. Is it better to use trigger or to write the insert query
> in the SP for every table itself.
>



Report this thread to moderator Post Follow-up to this message
Old Post
Uri Dimant
03-01-06 01:23 AM


Re: Trigger or SP
Hi Uri,
The purpose is to keep a track of all the new records added in any
table and storing the primary key in 1 common table. So my question is
that..... Is it better to use trigger in this situation (to insert
record in the common table) or to put the insert query for the common
table directly in the insert SP 's of the tables?
My question is coz its believed that use of trigger should be
avoided...

Please tell if u need any further clarification.
Thanks a lot..:)


Report this thread to moderator Post Follow-up to this message
Old Post
Adarsh
03-01-06 01:23 AM


Re: Trigger or SP
Hi
SP


"Adarsh" <shahadarsh@gmail.com> wrote in message
news:1141032494.303581.312640@t39g2000cwt.googlegroups.com...
> Hi Uri,
>   The purpose is to keep a track of all the new records added in any
> table and storing the primary key in 1 common table. So my question is
> that..... Is it better to use trigger in this situation (to insert
> record in the common table) or to put the insert query for the common
> table directly in the insert SP 's of the tables?
> My question is coz its believed that use of trigger should be
> avoided...
>
> Please tell if u need any further clarification.
> Thanks a lot..:)
>



Report this thread to moderator Post Follow-up to this message
Old Post
Uri Dimant
03-01-06 01:23 AM


Re: Trigger or SP
Can u please tell me why we should avoid using Triggers?

Thanks.


Report this thread to moderator Post Follow-up to this message
Old Post
Adarsh
03-01-06 01:23 AM


Re: Trigger or SP
Well, it depends on how often youb tables get updated/inserted and how many
rows are affected?
If you do the inserting within SP it is really easy to put insert  a new row
into an audit table just after your inserting.

BTW , in SQL Server 2005 there is a new feature OUTPUT clause  to allow
audit tables

create table mytable (col1 int identity not null primary key, col2  int not
null unique )
create table #audit (col1  int not null, col2   int not null)

insert into mytable (col2)
output inserted.col1  , inserted.col2    into #audit
select o.object_id from sys.objects as o

select * from #audit

go




"Adarsh" <shahadarsh@gmail.com> wrote in message
news:1141043938.297582.177890@z34g2000cwc.googlegroups.com...
> Can u please tell me why we should avoid using Triggers?
>
> Thanks.
>



Report this thread to moderator Post Follow-up to this message
Old Post
Uri Dimant
03-01-06 01:23 AM


Re: Trigger or SP
ok Thanks a lot Uri... :)... It helped me a lot


Report this thread to moderator Post Follow-up to this message
Old Post
Adarsh
03-01-06 01:23 AM


Re: Trigger or SP
Hi Uri,
When I add WHERE CLAUSE IN UPDATE query the OUTPUT doesn't work.

This code works :
DECLARE @OldProposal TABLE
(ProposalDesc varchar(200))

UPDATE tbl_Proposal SET ProposalDesc = 'yu'
OUTPUT Deleted.ProposalDesc INTO @OldProposal
SELECT * FROM @OldProposal

and this code doesn't work:

DECLARE @OldProposal TABLE
(ProposalDesc varchar(200))

UPDATE tbl_Proposal SET ProposalDesc = 'yu' WHERE ProposalID=9;
OUTPUT Deleted.ProposalDesc INTO @OldProposal WHERE ProposalID=9;
SELECT * FROM @OldProposal


Report this thread to moderator Post Follow-up to this message
Old Post
Adarsh
03-01-06 01:23 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

MS SQL Server archive

Show a Printable Version Email This Page to Someone! Receive updates to this thread
Microsoft SQL Server
Access database support
PostgreSQL Replication
SQL Server ODBC
FoxPro Support
PostgreSQL pgAdmin
SQL Server Clustering
MySQL ODBC
Web Applications with dBASE
SQL Server CE
MySQL++
Sybase Database Support
MS SQL Full Text Search
PostgreSQL Administration
SQL Anywhere support
DB2 UDB Database
Paradox Database Support
Filemaker Database
Berkley DB
SQL 2000/2000i database
ASE Database
Forum Jump:
All times are GMT. The time now is 05:29 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006