473,465 Members | 1,419 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Trigger in a certain period of time of day

25 New Member
Hi all,

I have two tables A(a1,a2,a3), B(b1,b2,b3) and a period of time delta t [t1,t2].

When it is between t1 - t2 of time, if there is a row inserted in table A, the field b1 of table B will be updated such as b1=b1+1.

Moreover, I also have a web application which can assign value for t1, t2 through an aspx page.

Could you tell me how to do that?

Thank kiu so much
Dec 8 '09 #1

✓ answered by ck9663

You have to create a trigger in UpdateInfo. You can either:

1. Create an INSTEAD OF trigger, check the system date when it fires then issue a return if it's outside of the range you need.
2. Create a AFTER trigger, use TRANSACTION, check the system date and issue a ROLLBACK then RETURN if it's outside of range. If it's within the range, proceed with the trigger and issue a COMMIT at the end before issuing a RETURN.

Happy Coding!!!

--- CK

7 4419
debasisdas
8,127 Recognized Expert Expert
Kindly post the code that you are working on.

what is the relation between the tables ?
Dec 8 '09 #2
nbiswas
149 New Member
Either u can go ahead with a job scheduler or write a window service that will monitor the application and will do the work within the t1 - t2 period
Dec 8 '09 #3
Mai Phuong
25 New Member
@nbiswas: in fact, I am writting a web application.

Yep, I will describe it more specific.

At the beginning point I have a trigger as following:

Expand|Select|Wrap|Line Numbers
  1. CREATE TRIGGER AddRow
  2. ON Demo
  3. FOR INSERT
  4. AS 
  5.     UPDATE UpdateInfo    
  6.     set new=new+1
  7.     where id=1
This trigger is related to table Demo and table UpdateInfo. UpdateInfo is created as following:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE UpdateInfo
  2. (ID    int    primary key,
  3. new    int,
  4. click    int)
  5.  
Customarily, whenever there is a row inserted to Demo, there is an update in field [new] of UpdateInfo, but I want that this trigger just works, for example, from 1:00 am to 6:00 am.

If this has been done, I then want to customize the time from an aspx page.

That all I want to do but still do not know how.

Thanks for your helping!
Dec 8 '09 #4
ck9663
2,878 Recognized Expert Specialist
You have to create a trigger in UpdateInfo. You can either:

1. Create an INSTEAD OF trigger, check the system date when it fires then issue a return if it's outside of the range you need.
2. Create a AFTER trigger, use TRANSACTION, check the system date and issue a ROLLBACK then RETURN if it's outside of range. If it's within the range, proceed with the trigger and issue a COMMIT at the end before issuing a RETURN.

Happy Coding!!!

--- CK
Dec 8 '09 #5
Mai Phuong
25 New Member
Because I am a beginner in sql server, I will be very appreciate if you could give me a more specific example.

The most important thing I wonder now is how can I check the system time such as wether it is between 0:00 am and 6:am or not?

I have realized that sql server 2005 has keyword "time", but it doesn't seem to be a data type.
Dec 10 '09 #6
ck9663
2,878 Recognized Expert Specialist
Here's an article about the trigger.

Here are some basics of dates:

How SQL Programmers Choose their Dates

The Basics of Dates

How do SQL Server Programmers Search for Their Dates?
Dec 10 '09 #7
Mai Phuong
25 New Member
Your help is so useful!

Finally, I used AFTER TRIGGER, and to check time I used datepart() function.

Have a good day!
Dec 11 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: RobertGl | last post by:
Hi everybody! My problem is as following: I have a trigger which fires on delete of a table row. The body of the trigger checks and manipulates entries in other tables. If the entries have...
1
by: blueyonder news | last post by:
Can anyone offer any advice. I was wondering whether MS SQL server offered any facilities to trigger an event after a period of time had lapsed? e.g. once a week check data and if it is out of date...
7
by: rkrueger | last post by:
Given the following 3 Tables: CREATE TABLE ( NOT NULL , NOT NULL CONSTRAINT DEFAULT (getdate()), NULL , CONSTRAINT PRIMARY KEY CLUSTERED (
1
by: Philippe Lang | last post by:
Hello, Dropping a trigger is permitted if the user is the owner of the table for which the trigger is defined. In a plpgsql function, used by different users, I need to disable some triggers...
1
by: abhi.10dulkar | last post by:
Hi guys, This might be simplest thing, but I am newbie to databases. I need to find out only rows modified within certain time period from a database. As I undertand a way out could be adding...
13
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables...
1
by: djdevx | last post by:
Dear all PostgreSQL xperts! Hi, I am newbie in PostgreSQL. I am currently developing an app that use PostgreSQL as a BackEnd Database. Now I am having problem with the function trigger since last...
22
by: DreamersDelight | last post by:
Hi, I'm stuck on this problem and I can't find a sollution. I'm going to try and explain this step by step. 1 After certain rows get updated with a certain value. I don't know wich rows in...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.