CodeChargeMVP
Posts: 473
|
| Posted: 05/03/2010, 4:59 AM |
|
Hello Everybody,
¿did you had a good weekend?
Well, the issue:
I´ve got two text box "a code" and a "year" which both can´t be repeated on database,
(I know I know create a primary key on database with both fields,
but on database the table has another field auto incremet as primary key
and we want to stand it that way)
So, i´m wondering ¿can i create a validation rule from codecharge for those text box
that avoid than code and year be repeated on database?
¿if it´s possible? ¿can i get info anywhere about what to put into validation rule field?
Greets
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 05/04/2010, 9:12 PM |
|
CodeChargeMVP
What version of MySQL are you running?? I thinking that you might be able to create a unique column for the year. This means that you will end up with a primary key and a unique column.
|
 |
 |
CodeChargeMVP
Posts: 473
|
| Posted: 05/05/2010, 2:48 AM |
|
Quote mamboBROWN:
CodeChargeMVP
What version of MySQL are you running?? I thinking that you might be able to create a unique column for the year. This means that you will end up with a primary key and a unique column.
Hello mamboBROWN,
I´m running PHPMy Admin 3.1.1
Primary Key (Auto Increment) - Code - Year
1 46015 - 2007
2 46015 -2010
3 28800 -2007
4 46015 -2007
We want to avoid row number 4.
If I change the year as unique column row number 3 won´t be possible, isn´t?
So the pair code-year shouldn´t be repeatead,so that´s what I´m thinking over some validation
rule or anything.
Maybe now I´ve explain it better.
¿Any Suggestion?
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 05/06/2010, 3:07 PM |
|
CodeChargeMVP
What is the version of MySQL (4.x or 5.x) not the version of phpMyAdmin?
To answer your original question, yes you can create your own validation rule but it would be easier to let the database do the heavy lifting. Maybe what you want is a unique index (which allows you to have multiple columns). Then all you would have to do is determine how you will handle an error if a someone tries to add a duplicate record to the table. You also could create triggers to do the same thing for you too (but that depends on the version of MySQL that you have). You definitely have some options.
|
 |
 |
CodeChargeMVP
Posts: 473
|
| Posted: 05/07/2010, 3:10 AM |
|
Quote mamboBROWN:
CodeChargeMVP
What is the version of MySQL (4.x or 5.x) not the version of phpMyAdmin?
To answer your original question, yes you can create your own validation rule but it would be easier to let the database do the heavy lifting. Maybe what you want is a unique index (which allows you to have multiple columns). Then all you would have to do is determine how you will handle an error if a someone tries to add a duplicate record to the table. You also could create triggers to do the same thing for you too (but that depends on the version of MySQL that you have). You definitely have some options.
I´m working over MySql 5.x,
As you suggest I´ve create an unique index with two colums so now it works as we expected,
I remind triggers on oracle, it has to be funny on mysql, but i let that for the future.
Database Error: Entrada duplicada '46015-2007' para la clave 'codano'
¿Would you mind take a look to my other post about ajax and sql?
Thank you very much.
_________________
Best Regards
Entrepeneur | NT Consultant
|
 |
 |
|