Sunday, February 26, 2012

dynamic trigger

I have created three trigger on three table. But the table names change
every year. Instead of changing 3 trigger every year, how can I change it
more efficient? Thanks.> I have created three trigger on three table. But the table names change
> every year. Instead of changing 3 trigger every year, how can I change it
> more efficient? Thanks.
Um, by not changing your table names?|||Yes, I mean by not changing the table name in the triggers. Like a global
constant. Say I set up currentyear = 2004 and next year is I set up
currentyear = 2005 and I don't need to change 2004 to 2005 every where.
"Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:es1NG$p1EHA.3000@.TK2MSFTNGP15.phx.gbl...
> Um, by not changing your table names?
>|||If you drop/recreate the tables, you must do the same with the triggers. You
could put all of the code in strings in the trigger , and use the exec
command... You might consider putting most of the common code in a stored
procedure, and calling the sp from the trigger.
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
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:OWhhbjp1EHA.164@.TK2MSFTNGP10.phx.gbl...
> I have created three trigger on three table. But the table names change
> every year. Instead of changing 3 trigger every year, how can I change it
> more efficient? Thanks.
>|||Sorry, I clicked too soon..
It would probably be worthwhile for you to try to reconsider the design...
perhaps you could use the same tablename in production, and remove annual
data to a history table at the end of the year...
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
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:OWhhbjp1EHA.164@.TK2MSFTNGP10.phx.gbl...
> I have created three trigger on three table. But the table names change
> every year. Instead of changing 3 trigger every year, how can I change it
> more efficient? Thanks.
>|||Hi
If you make the structure so complicated, then you need to live with high
maintenance.
Why don't you create one table, instead of one for each 2003, 2004, 2005 etc
and have one column that identifies the year. That would be a correct
relational database design.
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
""Allen Iverson"" <no_spam@.bk.com> wrote in message
news:#lthlpq1EHA.3376@.TK2MSFTNGP12.phx.gbl...
> Yes, I mean by not changing the table name in the triggers. Like a global
> constant. Say I set up currentyear = 2004 and next year is I set up
> currentyear = 2005 and I don't need to change 2004 to 2005 every where.
> "Aaron [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
> news:es1NG$p1EHA.3000@.TK2MSFTNGP15.phx.gbl...
>|||Thanks, Mike. Unfortunately the table name is bound to the vendor system
and there is not much thing I can do with the table name. I just don't want
to change the trigger on this table and the table name changes every year
according to the year. Any workaround?
"Mike Epprecht (SQL MVP)" <mike@.epprecht.net> wrote in message
news:uRaQo2t1EHA.2568@.TK2MSFTNGP10.phx.gbl...
> Hi
> If you make the structure so complicated, then you need to live with high
> maintenance.
> Why don't you create one table, instead of one for each 2003, 2004, 2005
> etc
> and have one column that identifies the year. That would be a correct
> relational database design.
> Regards
> --
> Mike Epprecht, Microsoft SQL Server MVP
> Zurich, Switzerland
> IM: mike@.epprecht.net
> MVP Program: http://www.microsoft.com/mvp
> Blog: http://www.msmvps.com/epprecht/
> ""Allen Iverson"" <no_spam@.bk.com> wrote in message
> news:#lthlpq1EHA.3376@.TK2MSFTNGP12.phx.gbl...
>

No comments:

Post a Comment