I will try the check, they may get what I want.  Thanks!

-----Original Message-----
From: [email protected] [mailto:[email protected]] 
On Behalf Of Igor Tandetnik
Sent: Wednesday, February 08, 2012 12:39 PM
To: [email protected]
Subject: Re: [sqlite] Question on the use of triggers

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

Disclaimer****
This email is confidential and intended solely for the use of the individual to 
whom it is addressed.  Any views or opinions presented are solely those of the 
author and do not necessarily represent those of St. Claire Regional Medical 
Center.  If you are not the intended recipient, be advised that you have 
received this email in error and that any use, dissemination, forwarding, 
printing or copying of the email is strictly prohibited.  If you received this 
email in error please notify the St. Claire Regional Helpdesk by telephone at 
606-783-6565.
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to