edvinson
asked on
Function Needed
I need a function that will delete records from X number of tables with a common uniqud id.
For instance, I have 4 tables - photos, items, stats, equipment
each of them has a field called equipment_id (which is the primary key).
Now, I want to have one function where I pass the id and it deletes all in a table with that id. Those table names are just a sample, in the function I need to be able to pass the names.
Please remember, the Number of tables I will pass to the function will vary.
Thanks!!
For instance, I have 4 tables - photos, items, stats, equipment
each of them has a field called equipment_id (which is the primary key).
Now, I want to have one function where I pass the id and it deletes all in a table with that id. Those table names are just a sample, in the function I need to be able to pass the names.
Please remember, the Number of tables I will pass to the function will vary.
Thanks!!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Very close to what I need, mgh_mgharish .
And thanks fot the tips Terref.
Here's how I would *like* to call the function:
deletefromtables("myunique idFieldNam eHere",myU niqueValue Here,"phot os","items ","stats", "equipment ");
And thanks fot the tips Terref.
Here's how I would *like* to call the function:
deletefromtables("myunique
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The echo at the bottom is just so you could see the result, just remove it in the real function!\
ms!
ms!
ASKER
sweet. thanks!
I already used mgh_mgharish's solution in our project ( by figuring out the answer myself ) but s/he never responded to my last post.
I will keep your solution also!
Mind if I split the points?
I already used mgh_mgharish's solution in our project ( by figuring out the answer myself ) but s/he never responded to my last post.
I will keep your solution also!
Mind if I split the points?
I've written a similar function for a client (It is copyrighted code, so I can't give it to you unfortunately).
What I did was
A show tables query and use that result to loop through al the tables with a describe query. Use that result to check if primary key exists and perform the appropriate action on that table.
Hope this will help