Jump to content

SQL Integrity Contraints


mattclements

Recommended Posts

Hey,

I am looking at modifying my SQL Script to include an Integrity Contraint for my A-Level Project. One table includes a Behaviour Code as the Primary Key. I want this to be displayed as LL00 (2 Composery letters, followed by 2 composery numbers). I think it should be something like:

 

ALTER TABLE behaviour_code
  Then some Integrity Constraint

 

Cheers in advance.

Matt

Link to comment
Share on other sites

  • 2 weeks later...

CHECK is not a valid part of MySQL (yet, maybe v6.0)

Thus your problem might be resolved by using triggers instead. However you're going to have to split up your column and parse it (in the trigger) and reject the INSERT/UPDATE based on that.

http://dev.mysql.com/doc/refman/5.0/en/triggers.html

 

The above url should get your started with triggers. And you might consider using a REGEX http://dev.mysql.com/doc/refman/5.0/en/regexp.html to check if the value is in the format you are expecting.

Link to comment
Share on other sites

Hey,

Yer with some more research I found out the same.... This isn't going to have to be a "production" database as it's just for an assignment. Ive got an extention to finish this off....

 

Anyway... So far im thinking:

 

ALTER TABLE students
CONSTRAINT form
CHECK (form LIKE 10LLa);

 

Basically I only want users to be able to enter 1 Optional Number, then 1 Compulsary Numbers, then 2 Compulsary Letters, followed by 1 Optional Letter... Such as:

13JC

or 14JCa

or 9JC

or 9JCa

Also is there any way of just limiting the number values to be between 9-14?

 

Thanks,

Matthew

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.