Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

multi table delete using joins
i have three tables:

User [id, name, surname, email]
User_Login [id, login_id, password]
User_Privilege [id, Privilege_Level]

(id is pk)

As mysql doesn't support multi table inserts, when i add a user i
am having to call 3 functions, to add the data to each relevant
table.

What i am working on, is if there was an error, i am trying to
simulate a rollback.

My function looks like this:
PHP:
Function AddUser { status InsertPersonalDetails(); if(status == false) { return false; } status InsertLoginDetails(); if(status == false) { //need to delete information inserted into PersonalDetails (User) table Rollback(); return false; } status InsertPrivilegeDetails(); if(status == false) { //now need to delete info from PersonalDetails (User) table and LoginDetails (User_Logintable Rollback(); return false; } }
The help i need is with the function Rollback - i am looking to perform a multi-table delete, using a join, but i can't quite figure it out. What i am looking for is one sql statement that can look for any null values in a completely joined record - if its null, then the insert must've failed, therefore delete the record and its relevant joined data. eg, If the first two inserts are ok, then the third insert creates an error, it will delete the user information that was entered in the user details and the user login tables. An error generated in the first insert is ok as it will break from the function. I have written the following: SELECT user.* from user LEFT JOIN user_privilege ON user.id = user_privilege.id WHERE user_privilege.privilege_level IS NULL i think this is ok (can someone confirm for me?), but i can't translate it into a delete statement. Thanks for the help! ---------------------------------------- The post originated from PHP Freaks: ---------------------------------------- http://www.phpfreaks.com http://www.phpfreaks.com/forums

Report this thread to moderator Post Follow-up to this message
Old Post
skinny monkey
08-18-04 08:57 PM


Re: multi table delete using joins
Have you looked at

http://www.mysqlfreaks.com/mysql/ma...agridguide.html easy
data tables - and more

----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums



Report this thread to moderator Post Follow-up to this message
Old Post
Barand
08-18-04 08:57 PM


Re: multi table delete using joins
i was aware that you could only use transactions on innodb & DBD
table types, whereas the one i'm using is isam, hence the need to
emulate a rollback function.



----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
http://www.phpfreaks.com
http://www.phpfreaks.com/forums



Report this thread to moderator Post Follow-up to this message
Old Post
skinny monkey
08-18-04 08:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Forum Jump:
All times are GMT. The time now is 04:45 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.