Adding foreign key in MySQL
This sql sintax can create link betwen key in some tables. Please used in InnoDB only. Here the code:
ALTER TABLE child_table_name
ADD FOREIGN KEY (P_ID)
REFERENCES parent_table_name (P_ID)
#example:
ALTER TABLE member_detail
ADD FOREIGN KEY (username)
REFERENCES member (username)
#foreign key will be deleted/updated if primary key deleted/updated
ON DELETE CASCADE ON UPDATE CASCADE
#parent will not be deleted if any child row exist
ON DELETE RESTRICT
#The script will be:
ALTER TABLE member_detail
ADD...
Thursday, August 21, 2014
Subscribe to:
Posts (Atom)
Popular Posts
- Resize and Crop Image In PHP
- Find Unmatched Records Between Two Table in MySQL
- Adding foreign key in MySQL
- Find Duplicate Entries in MySQL
- Limiting Words Number In PHP
- Find All Directory Or File Recursive In PHP
- Chmod File Only Or Directory Only Recursively
- Convert DateTime To Your Prefer Timezone
- Auto Detect URL in Text Then Make Clickable
- Validate Email Address and Domain in PHP
Copyright © 2025
PHP Tutorial | Powered by Blogger
Design by Azmind.com | Blogger Template by NewBloggerThemes.com