u01jmg3
09-19-2008, 06:21 PM
Below is the code so far for my 2 tables including some data which works fine but what I want to know is how I get the auto_increment of earrings(product_id) to respect necklaces(product_id) and vice versa such that product_id is unique over both tables???
CREATE TABLE earrings (
product_id int(5) unsigned zerofill NOT NULL auto_increment,
description varchar(100) NOT NULL,
metal varchar(50) NOT NULL,
size varchar(50) NOT NULL default '0cm',
colours varchar(50) NOT NULL,
price decimal(5,2) NOT NULL default '0.00',
category varchar(25) NOT NULL,
UNIQUE KEY product_id (product_id)
);
CREATE TABLE necklaces (
product_id int(5) unsigned zerofill NOT NULL auto_increment,
description varchar(100) NOT NULL,
type_of_fastener varchar(50) NOT NULL,
length varchar(50) NOT NULL default '0cm',
colours varchar(50) NOT NULL,
price decimal(5,2) NOT NULL default '0.00',
category varchar(25) NOT NULL,
UNIQUE KEY product_id (product_id)
);
INSERT INTO earrings (product_id, description, metal, size, colours, price, category) VALUES
('00001', 'Push through earrings with glass beads for pierced ears.', 'Sterling silver.', '2cm drop.', 'Pink/blue.', '4.50', 'earrings'),
('00002', 'Hoop earrings with wooden beads for pierced ears.', 'Niobium (hypoallergenic copper lookalike).', '3cm hoop.', 'Blue/copper.', '5.00', 'earrings');
INSERT INTO necklaces (product_id, description, type_of_fastener, length, colours, price, category) VALUES
('00003', '2cm amethyst donut pendant on satin cord with glass and silver beads and Chinese knotting.', 'Sliding knot fastener.', 'Length adjustable 30-40cm.', 'Purple/green.', '15.00', 'necklaces'),
('00004', 'Fused glass bead with copper and glass beads on a leather thong.', 'Copper barrel fastener.', 'Length 30cm.', 'Pink/orange.', '12.00', 'necklaces');
CREATE TABLE earrings (
product_id int(5) unsigned zerofill NOT NULL auto_increment,
description varchar(100) NOT NULL,
metal varchar(50) NOT NULL,
size varchar(50) NOT NULL default '0cm',
colours varchar(50) NOT NULL,
price decimal(5,2) NOT NULL default '0.00',
category varchar(25) NOT NULL,
UNIQUE KEY product_id (product_id)
);
CREATE TABLE necklaces (
product_id int(5) unsigned zerofill NOT NULL auto_increment,
description varchar(100) NOT NULL,
type_of_fastener varchar(50) NOT NULL,
length varchar(50) NOT NULL default '0cm',
colours varchar(50) NOT NULL,
price decimal(5,2) NOT NULL default '0.00',
category varchar(25) NOT NULL,
UNIQUE KEY product_id (product_id)
);
INSERT INTO earrings (product_id, description, metal, size, colours, price, category) VALUES
('00001', 'Push through earrings with glass beads for pierced ears.', 'Sterling silver.', '2cm drop.', 'Pink/blue.', '4.50', 'earrings'),
('00002', 'Hoop earrings with wooden beads for pierced ears.', 'Niobium (hypoallergenic copper lookalike).', '3cm hoop.', 'Blue/copper.', '5.00', 'earrings');
INSERT INTO necklaces (product_id, description, type_of_fastener, length, colours, price, category) VALUES
('00003', '2cm amethyst donut pendant on satin cord with glass and silver beads and Chinese knotting.', 'Sliding knot fastener.', 'Length adjustable 30-40cm.', 'Purple/green.', '15.00', 'necklaces'),
('00004', 'Fused glass bead with copper and glass beads on a leather thong.', 'Copper barrel fastener.', 'Length 30cm.', 'Pink/orange.', '12.00', 'necklaces');