Set up multiple picture table Good_pic (the Product ID in) is a foreign key. Refer to the ID in the Goods commodity table when deleting the item. Delete multiple pictures together.
Source: Internet
Author: User
#商品id primary Table
CREATE TABLE ' goods ' (
' ID ' INT (one) UNSIGNED auto_increment not NULL,
' Data ' VARCHAR not NULL DEFAULT ',
PRIMARY KEY (' id ')
) Type=innodb;
#商品多图片从表
CREATE TABLE ' Good_pic ' (
' ID ' INT (one) UNSIGNED auto_increment not NULL,
' Goodid ' INT (one) UNSIGNED not NULL DEFAULT ' 0 ',
' Pic ' VARCHAR not NULL DEFAULT ',
PRIMARY KEY (' id '),
INDEX (' Goodid '),
FOREIGN KEY (' goodid ') REFERENCES ' goods ' (' ID ') on DELETE CASCADE
) Type=innodb;
INSERT into ' goods '
(' id ', ' data ')
VALUES
(' 1 ', ' Audi '),
(' 2 ', ' Changan '),
(' 3 ', ' Land Rover ');
The Product ID cannot be modified because the picture table is set to a foreign key (Specify a field of its own, with the same type). Refer to the ID in the Product goods table, when deleted
FOREIGN KEY (' goodid ') REFERENCES ' goods ' (' ID ') on DELETE CASCADE
So also can not directly delete the commodity table, you may first delete pic picture table foreign key. or delete the entire pic picture table, so there is no restriction to the commodity table
DROP TABLE Goods
Set the multiple picture table Good_pic (good_id in) as a foreign key. Refer to the ID in the Goods commodity table when deleting the item. Delete multiple pictures together.
01 Product and picture table engine must be set to InnoDB to function
02 Picture table. Commodity ID field type. Copy the type of commodity ID (must be the same)
03 Picture table must be indexed index (' Goodid '),
FOREIGN KEY (' goodid ') REFERENCES ' goods ' (' ID ') on DELETE CASCADE
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.