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?
Hi All,

I have been working with SQL Server for some time - but until now
haven't tried to implement a trigger and am not sure if this is an
appropriate use.  Any advice would be greatly appreciated.

I have this table:  almis.dbo.aadata_x

when almis.dbo.aadata_x is updated, I want to automatically be able to
update a table in another database using this sql (only pulling
specifics from this table - not everything):

insert into dbname.dbo.tablename
select stfips as statefips, right(area, 3) as countyfips, periodyear,
race, gender, cenoccgrp, population, laborforce, emplab, unemp,
unemprate, pctpop, pctlabforce, pctemplab, pctunemp, pcttotlabforce,
pcttotemplab, pcttotunemp from aadata_x
where areatype = 04 and periodyear = 2000
and stfips = 18

I apologize in advance if this is too basic of a question -- but this is
something I need to be able to do in many cases .. on update of table1
. update certain fields in another table - perhaps in the same
database, perhaps not.

Again - thanks for any input you might be able to give me.

B


*** Sent via Developersdex http://www.droptable.com ***

Report this thread to moderator Post Follow-up to this message
Old Post
Bethany Holliday
01-24-06 06:23 PM


Re: Trigger?
Bethany Holliday  wrote:
> Hi All,
>
> I have been working with SQL Server for some time - but until now
> haven't tried to implement a trigger and am not sure if this is an
> appropriate use.  Any advice would be greatly appreciated.
>
> I have this table:  almis.dbo.aadata_x
>
> when almis.dbo.aadata_x is updated, I want to automatically be able to
> update a table in another database using this sql (only pulling
> specifics from this table - not everything):
>
> insert into dbname.dbo.tablename
> select stfips as statefips, right(area, 3) as countyfips, periodyear,
> race, gender, cenoccgrp, population, laborforce, emplab, unemp,
> unemprate, pctpop, pctlabforce, pctemplab, pctunemp, pcttotlabforce,
> pcttotemplab, pcttotunemp from aadata_x
> where areatype = 04 and periodyear = 2000
> and stfips = 18
>
> I apologize in advance if this is too basic of a question -- but this is
> something I need to be able to do in many cases .. on update of table1
> . update certain fields in another table - perhaps in the same
> database, perhaps not.

CREATE TRIGGER trigger_name
ON table
AFTER UPDATE
AS

insert into dbname.dbo.tablename
select stfips as statefips, right(area, 3) as countyfips, periodyear,
race, gender, cenoccgrp, population, laborforce, emplab, unemp,
unemprate, pctpop, pctlabforce, pctemplab, pctunemp, pcttotlabforce,
pcttotemplab, pcttotunemp
from aadata_x
where areatype = 04 and periodyear = 2000 and stfips = 18

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

Report this thread to moderator Post Follow-up to this message
Old Post
MGFoster
01-25-06 01:24 AM


Sponsored Links





Last Thread Next Thread
Post New Thread

Microsoft SQL Server forum 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 03:58 AM.

 
Mobile devices forum | Database support forum archive




Copyrights DropTable.com Database Support Forum 2004 - 2006