简体   繁体   中英

mySQL how to make one field in table dependant on if some other field has a value?

im bulding a website using html/php/js/mysql

I have a from on website where i need to enter Students ID and name of a course that student has passed, but some courses are dependant on other(example: i need to pass Calculus 1 before i can enter my Calculus 2 grade).

I need to check that data usig AJAX(example: if i try to enter grade from Calculus 2, but Calculus 1 is not completed(no grade) i need to msg an error) and if all conditions are fulfilled then i proceed to enter data.

What realy bugs me here: is there a way so i can make that kind of dependancy in mySQL? (i want to make Calculus 2 dependant on Calculus 1 value).

I hope that someone will understand my question and help me. Thanks

What you are asking is something that is supposed to be fulfilled by the logic of your program's code and not the SQL database. The database is only meant to store the data not doing logic based on said data.

The only kind of logic that SQL really does is transforming the data based on table aggregations or analyze data for patterns. It can do other stuff like force numbers in a certain table to never repeat.

Not allowing a table to have data unless another does is not part of the logic SQL handles. If you tell it to put data in a table then it will do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM