Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to do a 'trigger'

Author  Topic 

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2010-03-16 : 12:32:55
HI I have a table that gets sent from Production to my server, refreshed every night. There is one field in one table, that I need it to have a value. Currently, it is always blank. I would like to know the best way to have this field updated daily. Can it be done at the database level ? I am not sure if this is someting for a trigger or a program to run each day?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-16 : 12:34:54
what do you want it to be updated by?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-03-16 : 12:42:08
You want the field to be updated with what value ? a constant value ?

When do you want the field to be updated ? When the table gets "refreshed" ?

How is it get refreshed ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

AdamWest
Constraint Violating Yak Guru

360 Posts

Posted - 2010-03-16 : 14:16:57
For now, a constant value, 'Department'. Later on in the year, they will start entering the department so then we can stop the auto trigger.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-16 : 14:44:06
If you want something updated daily, then a trigger is not the way to go. You need to instead create a SQL Agent job that runs the UPDATE statement for you on a scheduled basis.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-03-17 : 01:20:43
if its for inserts then a default constraint on column will suffice which can removed later once they pass actual dept value

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2010-03-17 : 05:36:31
Sounds like the table gets kyboshed each night when the data is copied over, and you want to then change it to be "different" to the copied data?

Scheduled task would be OK provided it ran after the copy finished and before anyone accessed the data - sounds "fragile" to me.

I think it would be better that the process that copies the data over then executes some additional code that does any other "tidy up" tasks - like creating your "department" value.
Go to Top of Page
   

- Advertisement -