UPDATE With Related Tables?
I have a forum structure stored in a MySQL database and recent changes I made to a web site using it made it stop incrementing the "replycount" for threads (yup, pretty silly :-)) anyways, I am working on a stored procedure (or just an SQL statement) that I can call to recalculate the reply counts.
The two tables are structured like so:
mysql> describe thread;
+------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+----------------+
| tid | int(11) | NO | PRI | NULL | auto_increment |
| title | varchar(50) | YES | | NULL | |
| lastpost | datetime | YES | | NULL | |
| viewcount | int(11) | YES | | NULL | |
| replycount | int(11) | YES | | NULL | |
| author | int(11) | YES | | NULL | |
+------------+-------------+------+-----+---------+----------------+
6 rows in set (0.01 sec)
mysql> describe post;
+----------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------+------+-----+---------+----------------+
| tid | int(11) | YES | | NULL | |
| pid | int(11) | NO | PRI | NULL | auto_increment |
| authorid | int(11) | YES | | NULL | |
| body | text | YES | | NULL | |
+----------+---------+------+-----+---------+----------------+
4 rows in set (0.00 sec)
Is there a way to do an update query that will link the two tables, then group on the 'tid' field, then use the count result from the 'tid' field to inset into 'replycount'? Also, this is an example showing how the info is related, just in case I dont make it clear enough to understand:
SELECT thread.tid, thread.title, count(thread.tid)
FROM thread, post
WHERE thread.tid=post.tid
GROUP BY thread.tid
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
3 Related Tables In One Query?
I want have these 3 tables: - Properties : contains a list of properties - Images : contains images (the urls of) - Attributes : contains a key=>value pairing for properties, any number of per. What i need to do is: Get all the properties in the database get the Image relating to the property, where the Image:ID = Property:mainimg get ALL attributes relating to the property, where the Attrib:Property = Property:ID how would i do this? I am aware of how to join two tables, but what about with 3?
Related Tables In Database
I am reading Build Your Own Database Driven Website Using PHP and MySQL and I have a quick question. When it starts talking about many to many relationships how does mysql know that a column labled jokeid in the jokecategory table has the same value as the column id in the joketable.
Joining NON-Related Tables
Is it possible to join non-related tables? If I have one table called "community", how would I join it with the table "membership"? They don't have any related fields. I would like to display the data from the "membership" table in the "community" table: community ============== id members group **************** membership ============== memberspergroup feepergroup
How To Navigate Related Tables?
I have just installed the 5.1 connector with the visual studio plugin. I have 2 tables related to each other. I created a relationship for them using the designer. But when I navigate the 'names' table, the 'details' table doesn't move to the correct record with respect to the name. Actually, it doesn't move at all. The primary key in 'names' is phone. It is a foreign key in 'details'. What I want to happen is that when I go to name #2, the details that is shown must be for that name and not for the name #1.
Joining Tables Which Aren't Directly Related
I'm struggling to get my head round a SQL query and wonder if you might be able to help (I'm using MySQL version 4.1.20-1). I have three tables: accounts, items and invoices. CREATE TABLE accounts ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, ... PRIMARY KEY (id) ) ENGINE = InnoDB; CREATE TABLE items ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, accounts_id INT UNSIGNED, ... PRIMARY KEY (id), FOREIGN KEY (accounts_id) REFERENCES accounts (id) ON DELETE SET NULL ) ENGINE = InnoDB; CREATE TABLE invoices ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, items_id INT UNSIGNED, ... PRIMARY KEY (id), FOREIGN KEY (items_id) REFERENCES items (id) ON DELETE CASCADE ) ENGINE = InnoDB; Each account can have multiple items and each item can have multiple invoices. Hope you're with me so far? So here's the question. If I have an account ID, how do I get a list of invoice IDs for that account when accounts and invoices aren't directly related?
Front End For Updating Several Related Tables
Is there a simple front-end that would let me select records from multiple related tables and edit their field data? Right now, I am opening each table individually in mysql control center, entering the new record, or editing the existing one, then moving on to the next table. I know there’s got to be something better, and I am to busy (spelled overloaded) to create my own from scratch. I use python now for most of my sql scripts, and PHP on occasion, but could figure out and modify something simple if necessary.
Insert Data Into Related Tables
I'm sure that this question has been asked many a times but I can't find it, probably don't know the right keywords to find it. I am new to MySQL, working knowledge of MS Access, so quite a leap forward. I have 2 tables (for learning purposes) 1. pages page_id page_title ... 2. articles article_id page_id article_title ... If a create a new article_id for which a page_id does not already exist, what method must I use. Basically how can I create a new article and page entry simultaneuosly? Must I do 2 seperate inserts (is this when a transaction should be created) or one using some sort of join? How do I ensure that whatever auto-increment page_id number is created by the database is associated to my new article entry?
Count Related Records, But Show Records With NO Related Records Also
cl_items ======== it_id (pk) it_ownerid it_name cl_offers ======== off_id (pk) off_itid (fk) -> to it_id off_whoid My query needs to output ALL of the records in cl_items AND still show how many offers are on each item (from cl_offers) I can't get what I want through the GROUP BY because I want to show the records in cl_items which DO NOT have any offers on them yet also. Is there any way to do this with mysql only?
Update Multiple Tables?
situation: a user wants to change their username on my site and their username is littered accross many tables in the DB. If in every one of those tables i've got a static "user_id" column as well as the "username" column, what is the best way to update all of the different tables with the most efficiency?
Update - Mult Tables
Early experimentail stages with Databases. I have this little faq sys running on my dev server BUT just uiploaded to my host and what yer know it aint working.. two tables question and answers two "Poted vars" $an and $id I am trying to update the answer to a qu.... UPDATE answers,questions SET anstext = '$an' WHERE questions.ans_id = answers.id AND questions.id= '$id' I read that multiple tables was only suppoerted on later vers on Mysql...OR is my syntax just wrong
Update 3 Tables At A Time
i have 3 tables namely--- artist, journalist and songs. i try to update the flags in artist and journalist and try to update few fields from songs by firing foloowing qurries. update songs set sname='lala', sname2='my baby' where artistid=6; update artist set statusartist='new',flag1='updated' where artistid=6; update journalist set statusjourn='new',flag1='updated' where journid=4; when i fire the above querries individually they are excuted without any error. when i try to run these querries through my JSP application only the songs data is updated and the rest 2 tables are not. i tried to write 1 combined query including all 3 tables for this,but still it didnt work. can u please tell me a solution for this.
Best Way To Update Multiple Tables At Once
I need to update a few tables at once. I have a form, were I fill in some information about a concert, which updates thez concert-table. Next to this, I need to update the bands-table, the statistics-table, and some others. What would be the safest, and fastest way to achieve this?
Update Query Between Two Tables
I am having a problem with getting an update query to work. here's what I am using: Update stck Set vendor = 'items.vendor' where prtn = 'items.prtn' I am getting a items table not found error. I thought this is what I needed to do to update many records from one table to another.
UPDATE Linking Other Tables
I am trying to do a simple update function in mySql. NOTE. I am using version 3.0.9.4-beta I have 2 tables: Items and Sales_details I want to update a field called >Sales_value< in Sales_details table using value from Items called >Sell< times (*) >Sales_qty< from Sales_details table. This is the codes I have been trying: UPDATE Sales_details inner join Items on Sales_details.fk_Item_ID = Items.Item_ID SET Sales_details.Sales_value = (Sales_details.Sales_qty * Items.Sell) Error msg:[development_DB] ERROR 1064: You have an error in your SQL syntax near 'inner join Items on Sales_details.fk_Item_ID = Items.Item_ID SET Sales_details.S' at line 1 and UPDATE Sales_details SET Sales_details.Sales_value = (select (Sales_details.Sales_qty * Items.Sell) from Items inner join Sales_details on Items.Item_ID = Sales_details.fk_Item_ID) where Sales_details.fk_Item_ID = (select Item_ID from Items) Error msg:[development_DB] ERROR 1064: You have an error in your SQL syntax near 'select (Sales_details.Sales_qty * Items.Sell) from Items inner join Sales_detai' at line 2
How Do I Automatically Update Tables?
I need some very basic information and ,being new to mysql, am not sure what keywords to use to search for an answer. Would someone please tell me either where I can find the info I seek or what they keywords would be? I have created three tables and added foreign keys from tables 1 and 2 to table 3. Example: #1 person table person_id pr key #2 location table loc_id pr key #3 event table event_id pr key foreign keys: person_id & loc_id Please note that these table examples have more columns than what is being shown. When updating the event table, how do I get the foreign key colums to choose the correct person_id and loc_id and automatically update? So far, the mysql tutorial book does not address this in their examples so I must assume that the foreign key columns were updated manually. Others have told me that this can be done using forms and subforms. If this is so, how?. And, can it not be done also in mysql using the command line? If forms is part of the answer, I am familiar with them, having used them in my website. I am learning php and have created test forms to update my tables. So far, I can't get the tables to actually update although the php code states that I have connected to both the database and table but that is another issue. My point is that I have some knowledge of forms and php. I just can not find any info telling me how the forms, subforms, php and mysql may work together to automatically update the tables.
How To Update Tables Automatic?
I have a table with all FOREIGN KEYS pointing to tables with PRIMARY KEYS. But when i add data to base table(Primary Key) it should auto update the dereived(Foreign key) table
Live Update Of Tables
I do have the following problem: A local server running MySql includes the database A, another server in another region (connected to the internet) includes a mirror database of A. What I need is to live update the tables of the mirror database via a secure connection. Both networks have an internet connection.
Using Form To Update 2 Tables
how to change ths script below so it can update the same cells in another table aswell the current table. in other words updates two tables at the same time. <?php if ($submit) { require("db.php"); $con = mysql_connect("$db_host", "$db_user", "$db_pass"); $db = @mysql_select_db("$db_name",$con); $sql = "INSERT INTO support (prod_code,prod_name) VALUES ('$prod_code','$prod_name')"; $result = mysql_query($sql); echo "Thank you! Information entered. <a href=admin.php>Click Here</a> "; } else{ ?> <form method="post" action="<?php echo $PHP_SELF?>"> Product Code:<input type="Text" name="prod_code"><br> Product Name:<input type="Text" name="prod_name"><br> <input type="Submit" name="submit" value="Enter information"> </form> <?php } ?>
UPDATE Multiple Tables Difficulties
I've been creating a stock update system that needs to be integrated with an existing database. To update the stock I need 2 tables updated in the same query (unless there is better way). In one table, items_ordered, holds every single product that has been sold and has a field StockUpdated which holds a 1 or 0 depending on whether they have been stock counted already. This will stop future queries counting stock that has already been counted. i.e. the query will look and update each record that has a 0. So far the query is able to update this table successfully.....
Compare 2 Tables And Update One If A Match.
I have two tables "contact_tbl" and "address_tbl". I have a query that compares the email addresses between the two. If a match is found I need to update a specific field in "contact_tbl" with a value of 'yes'. My query is: SELECT * FROM contact_tbl INNER JOIN address_tbl ON contact_tbl.email = address_tbl.email; This works and I get a nice result set showing records where the email addresses match. I now need to update a field "status" in contact_tbl when there is a match. Have been tinkering with this for a while but not sure of the syntax and placement for the UPDATE code.
PROGRAM TO UPDATE DATA TABLES
I need to be able to DELETE selected record & LOAD DATA from a text file or Foxpro table, from a program that can run continuously. I've tried Foxpro, but FoxPro views are too slow. I have also tried issuing these command from Foxpro with an ODBC connection established, but that does not work at all. The object is to remove all records for a member and replace these records with records from a new file. Each transaction will be up to 50,000 records. I need to execute 2 commands: DELETE FROM parts WHERE parts.member_id="xxx" and LOAD DATA INFILE 'd:/xxx.txt' INTO TABLE parts
Can't Update Records When Using Linked Tables In Access
I have a linked table to MySQL 5.0 through MS Access 2003 that utilizes a timestamp field in order to prevent the #Deleted signature happening everytime I create a new record. However, when I attempt to update a previous record I receive the error message: "Reserved error (-7776)" and am subsequently prevented from updating any records. Please note, there are no errors when creating new records, only when I attempt to update an existing one. However, if I remove the timestamp field, updates occur without error. Has anyone else encountered this issue? How might I rectify it?
Slecting Related
I need to select 5 related products.... it should work like this: I have product with name Website Ezine Make Easy now I need to find 5 products based on words from product and based on that product category and if there is no 5 then to take rest of products from main category.... so far I have this: PHP SELECT * FROM products WHERE fullname LIKE "Website" OR fullname LIKE "and" OR fullname LIKE "Website and" OR fullname LIKE "Ezine" OR fullname LIKE "Website Ezine" OR fullname LIKE "and Ezine" AND section = ཉ' OR section IN (1,2,3,4,5,8,9,10,11,12,13) ORDER BY CHAR_LENGTH( fullname ) DESC LIMIT 0,5 unfortunately this is not good, I get some products which shouldn't be there.
Display Related Value
I'm displaying personnel actions data in a details page based on the ID of the personnel action record, but would like to display a value (Employee Name) from a related table (tblemployees) based on a payroll_num field in the details page. These two fields are related, payroll_num and payrollID(primary in tblemployees). How do I add both tables in my query or is this the right way to get this accomplished?
Related Table
I am trying to follow an example I found for creating two tables in a "related form" The code creates the two tables, however if I use PhpMYadmin to enter primary records in the first table, I get an error on trying to add a second record. Code:
Related Item
im currently working on a simple lyric page: I have 2 data : title and keyword when a user view a particular lyric, i want a related lyric by title & keyword to be display example data in database title Green Day Walking Alone Keywords(separated by commas) Green Day, walking alone, tabs, midi i use this code below but the result display only one title which is the same title as the currently viewed lyric SELECT title, keywords FROM lyrics WHERE title LIKE '%".$arr[title]."%' AND keywords LIKE '%".$arr[keywords]."%' how to fix this is my sql format correct ?
Date Related Topic
Is it possible to extract the month from the date("F") function and then save that in a database table as plain text?
Yet Another Zip Code Related Question
I'm new to MySQL and proximity searches so forgive my ignorance. I have the following query which works perfectly (which I got from a post here thank you very much) SELECT zip FROM zipcodes WHERE degrees(acos( sin( radians(zipcodes.latitude) ) * sin( radians(33.727807)) + cos( radians(zipcodes.latitude)) * cos( radians(33.727807)) * cos( radians(zipcodes.longitude - -84.41983) ) ) ) * 69.09 < 5 This returns a list of zipcodes Now I want to find every bookstore in that list. SELECT * FROM bookstores WHERE zipcode IN ( SELECT zip FROM zipcodes WHERE degrees(acos( sin( radians(zipcodes.latitude) ) * sin( radians(33.727807)) + cos( radians(zipcodes.latitude)) * cos( radians(33.727807)) * cos( radians(zipcodes.longitude - -84.41983) ) ) ) * 69.09 < 5) This gives me a syntax error.
DELETE With Related Table
I have a table (tableA), with a data field (saved as a VARCHAR in YYYY-MM-DD). I have a second table, tableB, which has a field with an int field which refers to the ID of tableA (or is null). I call this field tableB.idA I am trying to delete rows in tableA where the date is less than a specified value AND there is no reference to said row in tableB. But how to specify this in SQL. I tried : DELETE FROM tableA WHERE tableA.date <'2007-01-01' and tableB.idA!= tableA.id; only to get the exception Unknown table 'tableB' in where clause.
Delete Related Records
I have a typical setup with a master table that has a related table with many records per master record. Since MySql does not support sub-selects, how do I delete just the set of records I want? TABLE1 - Master id, name TABLE2 - Tran id,mast_id,item,price Tables are related via (TABLE1.id = TABLE2.mast_id) I wish I could do a: DELETE FROM table2 where mast_id IN (SELECT id FROM table1 WHERE name = 'fred'); If I'm only deleting one master record, then it is easy, one select to find the master.id then another to delete all table2 records with that mast_id. But, the problem I'm having is when I want to delete a batch of records from table1, I also want to get rid of all of the related records so I do not have any orphans.
Date Related Field
This may sound awkward, but I have a field that is of varchar(10) type with dates in the format mm/dd/yyyy Is there anyway to query on this table and sort by this field although its not of date type? I want to sort asc and desc but I am guessing I need to cast on the fly or something? I'd like to use this convention going forward (I know its stupid) It was done this way as an easy way out
Finding Cloest Related Number
I have a table filled with some colors the RGB values. I am trying to find the cloest related color by searching the table. I really have no idea, i thought at first using 'LIKE' but I dont think that is going to work properly. I setup the table to search either 1 deliminated column or 3 different columns, whichever would work best. ------------------------------------------------ | color | rgb | r | g | b | ------------------------------------------------ | aqua | 0,255,255 | 0 | 255 | 255 | | blueviolet | 138,43,226 | 138 | 43 | 226 | I dont know if theres anyway to do it but I am trying to find the cloest related color by searching by a user defined rgb. For instance... I want to search for the cloest color related to 130, 100, 200 it should return blueviolet because its the cloest related color out of the two.
JOIN Query Related Question...
I have two tables as shown below: Table 1: Actor.............................Table 2: Movie Field:...ID.....Last......First..............Field:...ID.....Last......Movie ...........1.....Willis......Bruce.......................1.....Willis......Die Hard ...........2 ....Cruze....Tom..........................2.....Cruze.....MI-III ...........3.....Pitt.......Brad ...........4 ....Depp.....Johnny Then I JOIN the tables with Query which works fine, following is the result: Field:...Last......First........Movie ..........Willis......Bruce......Die Hard ..........Cruze....Tom.........Cruze MI-III ..........Pitt.......Brad ..........Depp.....Johnny MY QUESTION: What JOIN option should I use so it would display data that are in both tables (such as Bruce Willis and Tom Cruze).
Forum Related Table Structure
I didn't know whether to post this in the php forum or mysql--we'll try this one: Suppose that I have a mysql-php based forum running. Users table (simplified) looks like: Users ------------ user_id (int, primary_key) username (varchar(30)) password (varchar(30)) read_post_ids (text) Currently, 'read_post_ids' is a comma-separated list of all the post ids that a user has clicked on, which are marked as such. Currently a php script is resposible for reading the list into an array, looping through to find values if needed, and on a write back to the db it takes the array and turns it back into a CSV string. Problem: The table isn't even in 1NF because of this field, and extra processing is going on. As an alternative, I have considered dropping 'read_post_ids' from this table, and starting a new table: Read_Post_Ids ------------- id read_post_id user_id This normals the tables and makes queries easier, but I worry about storage. Let's say I have 10,000 forum users, that on average read 20 posts per day. that is 200,000 table rows per day. In a year, I have 71,000,000 rows. If I index the fields (as I probably should for speed), the rows take up even more room. If I decide to only allow a user a maximum of 300 stored 'read posts' (for example), then I probably have to add a timestamp field so I can delete the older ids, which takes up even more space. So is there a preferred method here? I would prefer that the tables be normaled, but I worry about the table growing out of hand in terms of size, and at some point becoming slow.
Related Article Search (using Tags)
I am working on an article manager. For every article i have a tag defined (similar to flickr). For example when i access mysite.com/pages?page=1 then suppose it's tags are life,confidence,success,honesty Now below the actual article content i want to show all the articles avaiable in the database WHICH HAVE ANY ONE OF THE TAGS OR MORE TAGS ASSOCIATED WITH IT. That means any other article (in same table) should be displayed which have the same tag associated witrh them Table name: articles Database name: mysqldb So how do i write the search query?
Noob Sql: Find Related Posts
post id user title description created_at tag id post_id tag_name user "post" 1:M relationship with "tag" I don't think this is the right sql: select post_id from tag where user=user_id and tag_name in (tag1,tag2,tag3) inner join post on post.id = tag.post_id tag records: post_id: 1 tag_name: tag1 post_id: 1 tag_name: tag2 tag would have two records for post_id=1, where as post only has 1 record with id=1. Given a list of tags, I need to find the post that have those tags. Anyone know how I can do this? Basically what I am trying to do is, display related post.
Full Text Search Related I Think..
Apologies if this is a common thread, I'm not quite sure how to search for my problem, although I believe it's close to a full text search. I have strings comprised of words/spaces, let us say the words are A,B,C (These words are actually search keywords/tags). The words only appear once per string. For example the table looks like: "A" "A B" "A B C" My question is: How do I find the most common word ("A" in this case)? How do I find the second most common word ("B")?
Counting Records In Related Table
I'm trying to construct a single query that returns all records from one table plus a count of all corresponding records in another table. I have a table of members (members) and a separate table (traffic) that tracks what each member has downloaded from the website I've created. Here is the current SELECT statement I'm using: SELECT * , COUNT(*) AS traffic_count FROM `members` , `traffic` WHERE members.id = traffic.member_id GROUP BY members.id ORDER BY traffic_count This almost works for me. The problem is that it only returns results for the members who have corresponding records in the 'traffic' table. This is a great start but I'm trying to return all records from the 'members' table including a corresponding 'traffic_count' variable for each member. This means that for each member that has no entries in the 'traffic' table I'd like the 'traffic_count' variable to be 0.
Pull Related Info Using Subqueries
I'm creating a tool to browse a database of movie listings. The browser pulls up 25 results at a time, and you can page through them using 'Next' and 'Prev' tools. Pretty basic stuff. Here are my tables: movies directors comments movies_directors movies_comments etc... (primary key is movies.id) But here's where I'm stuck: for each film, I need to pull the movie info in 'movies', plus any related data from other tables, like this: The Lord of the Rings | Peter Jackson | 3 comments Episode II | George Lucas | 0 comments Indiana Jones | Steven Spielberg | 15 comments I seem to run into problems when I try to join info from all of these related tables. If there's a match, great. But, if not (like a movie with no comments), the movie is excluded from the result set. I've tried all sorts of SQL queries to make this work, but nothing seems to do the trick. SO, HERE'S MY QUESTION, IS THERE ANY WAY TO DO THIS QUERY WITHOUT SUBQUERIES/MYSQL 4.0? Or would the best approach be to use PHP to do all the subquery lookups?
Finding Token Among Recordsets (string Related)
I just found out how to find which recordsets have a keyword by using: SELECT * FROM othertrack WHERE MATCH (userresponse) AGAINST ('ebook'); Is this the smartest way to do it even with large records? If I use a fulltext index? I just care about performance and want to make sure this is the best way to search through thousands of records to find which ones contain a keyword 'ebook'
Select Multiple Instances Of A Related Field
Is it possible to write an SQL statement to export mutliple instances of a related field in a single record? For example, ContactsTable is related to ContactHistoryTable. I want to select the contact record and export 3 columns from the ContactHistory records containing the most recent ContactHistory.Type = Phone, most recent ContactHistory.Type = Appointemnt and ContactHistory.Type = Action
Query The Article Table And Get A Count Of All Related Comments
Could someone please help me with this query. I have two tables -- one for my articles and another for my comments. Comments are stored in the comments table with a corresponding article id. I want to query the article table and get a count of all related comments. The following query doesn't seem to work for me. Can you please suggest how I fix it? SELECT a.id AS id, a.title AS title, a.preview AS preview, a.thumbnail AS thumbnail, a.category AS category, a.timestamp AS timestamp, a.game AS game, count( b.id ) AS commentcount FROM article_table AS a, comment_table AS b LEFT JOIN comment_table ON a.id = b.article WHERE a.news = 'Yes' AND a.type = Ƈ' AND a.saved != Ƈ' GROUP BY b.article ORDER BY a.timestamp DESC LIMIT 5
Is Error Code 1053 Only And Always Related To Killing A Query
The code I am developping is cancelling a SQL SELECT query if the user finds that it's too long. I'd like to display to him that he successfully cancelled it. Can I rely on the error code 1053 that I receive after I performed a kill process (using the id of the process) ? The documentation of the error code 1053 says: SQLSTATE: 08S01 (ER_SERVER_SHUTDOWN) Message: Server shutdown in progress I am using ConnectorJ..
How To Remove The Related Privileges Of Accouts When Drop A Database?
I 'am using Mysql 5.0. When I drop a database, but the related accounts still exist, how can I remove the privieleges in these accounts which used to access this removed databases ?But I do not know which accounts can access db2 before. e.g. some accounts with select ,delete update to database db1 ,db2 and db3, when I drop db2, how to remove the privileges related db2 in these accounts ? but not impact on other accounts and databases ?
How To Cascade Delete Related Records Without Deleting The Main Record?
Let's say I have the following database tables: CREATE TABLE user ( id INT UNSIGNED NOT NULL PRIMARY KEY, username VARCHAR(20) NOT NULL, ) ENGINE = INNODB; CREATE TABLE user_email ( user_id INT UNSIGNED NOT NULL PRIMARY KEY, email VARCHAR(100) NOT NULL, FOREIGN KEY (user_id) REFERENCES user(id) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE = INNODB; CREATE TABLE user_phone ( user_id INT UNSIGNED NOT NULL PRIMARY KEY, phone VARCHAR(100) NOT NULL, FOREIGN KEY (user_id) REFERENCES user(id) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE = INNODB; What I want to do is delete all records in the 'user_email' and 'user_phone' tables without deleting the record in the user table. I have a database without nearly 20 tables with one-to-one and one-to-many relationships with the user record and I need a way to cascade delete records in relationship tables.
|