Jump to content

Unique Indexes?


shornesr

Recommended Posts

MySQL version - 4.1.20

 

I have three fields in the table rows...  FULL, AM and PM

 

If the FULL field has an entry I want to make it so AM cannot be filled and PM cannot be filled.

 

However, if AM is filled I want PM to be able to be filled as well and vica versa

Link to comment
Share on other sites

Actually, I just found a basic tutorial on triggers... thanks!

 

I can see how to update and instert, etc...

 

How would you prevent and entry from being made?

I suppose you could use a BEFORE INSERT trigger and check; to be honest, I'm not really using 5.0, so I haven't played much with them.

Link to comment
Share on other sites

Dude I don't think you can do it with the mysql version you have. This needs to involve a programming language for that.

 

Now with triggers you will looking at a before insert/update stmt.

If you are firing an insert I believe you can just insert FULL and not AM/PM

 

You know what just ensure the integrity via the programming language through the queries you fire.

 

Link to comment
Share on other sites

This would be much easier to do with your application code rather than MySQL.

 

Just do a quick SELECT first and see if there is data in FULL. If there is, stop your script from allowing someone to add data to AM or PM, etc. Build the logic into your application and use MySQL to store your information.

 

-Dan-

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.