Je ces bases de donnéesDéclare clé étrangère dans MySQL
=== Invoices ===
id
status
description
=== Invoice Items ===
id
invoice_id (FK)
item_name
description
Pour ce tableau, je l'ai fait cette commande MySQL
CREATE TABLE IF NOT EXISTS `nt_invoices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`status` varchar(45) NOT NULL DEFAULT '',
`description` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
CREATE TABLE IF NOT EXISTS `nt_invoice_items` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`invoice_id` int(11) NOT NULL,
`item_name` varchar(45) NOT NULL,
`description` text NOT NULL,
PRIMARY KEY (`id`),
KEY `invoice_id` (`invoice_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=12 ;
Mon problème est que je veux déclarer une clé étrangère dans la invoice_items
table et pour faire le invoice_id
la clé étrangère de invoices
id de la table. Alors, comment écrire cette commande? Toute aide et suggestions seront très appréciées.
+1 pour attraper la question MyISAM – drnewman