On 2/8/2012 12:30 PM, Tilsley, Jerry M. wrote:
I creating a new database and would like to use triggers on a couple of the
tables. Below are two of the tables I will be working with in the triggers;
CREATE TABLE accounts (mrn char(8), acct char(12), discharge_dt int, Primary
Key(acct), Foreign Key(mrn) references Patient_Info(mrn));
CREATE TABLE patient_info (name varchar(250), dob varchra(10), mrn char(8)
primary key not null);
I would like to create a trigger on the patient_info table that is a BEFORE
TRIGGER
BEFORE what? Before insert, before update, before delete?
that would verify that the MRN field is 8 characters AND starts with 'MR'.
What should happen when the requirements are met, vs. not met?
If you want to simply fail all attempts to enter a string that doesn't
match your pattern, you could just put a CHECK constraint on the column:
CREATE TABLE patient_info (name varchar(250), dob varchra(10),
mrn char(8) primary key not null CHECK(mrn like 'MR______'));
--
Igor Tandetnik
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users