- SELECT
- Order By Rand
- Concat Fields
- Between
- Regexp
- If Null
- Union
- Replace
- Using Syntax
- Substring
- DATE
- Get Date
- Date Format
- Today
- Month Day
- Date Parts
- ADMINISTRATION
-
Foreign Key
- Foreign Key Disable
- Innodb
- Create Database
- Create Table
- Add Column
- Add Index
- Data Type
- Primary Key
- Errors
- Indexes
- Mysqldump
- Table Definition
MYSQL PAGES -
LEVEL 3
Add foreign key
Foreign keys helps prevent admin input errors, producing a more accurate database. Using constraint any attempt to link to a record which does not already exist will fail.
ALTER TABLE article_log ADD FOREIGN KEY (article_id)
REFERENCES article (id) ON DELETE CASCADE;
Modify foreign key
SHOW CREATE TABLE catg_path;
CREATE TABLE `catg_path` (
`ancestor` int(10) unsigned NOT NULL,
`descendant` int(10) unsigned NOT NULL,
PRIMARY KEY (`ancestor`,`descendant`),
KEY `descendant` (`descendant`),
CONSTRAINT `catg_path_ibfk_1` FOREIGN KEY (`ancestor`) REFERENCES `catg` (`id`),
CONSTRAINT `catg_path_ibfk_2` FOREIGN KEY (`descendant`) REFERENCES `catg` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
;
ALTER TABLE catg_path DROP FOREIGN KEY catg_path_ibfk_1;
ALTER TABLE catg_path ADD FOREIGN KEY (ancestor) REFERENCES catg (id)
ON DELETE CASCADE;