I'm new to database and I have a question about a table with triggers or maybe a check constraint. I'm using SQL Server Mangagement studio.
I have the following table:
create table item(
startprice char(5) not null,
description char(22) not null,
start_date char(10) not null,
end_date char(10) not null,
indicator char(3) not null
);
What I'm trying to make is this trigger/constraint rule: indicator will get "no" if system date is earlier than start_date and end_date, and "yes" if system date is after start_date.
This is simple you have to use trigger with before insert option -
Following trigger is good to go in Oracle DB -
CREATE OR REPLACE TRIGGER item_insert_indicator
BEFORE DELETE ON item
For each row
begin
if :New.start_date > sysdate and :new.end_date > sysdate then
:New.indicator := 'no';
elsif :New.start_date < sysdate
:New.indicator := 'yes';
end if;
end;
This is just for your reference. for your database you can change keywords accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With