there are lets say 50 products and only 15 customers ok ?
so this new table needs to be
prod_id Cust1 Cust2 Cust 3..........Cust 10
001
002
003
....
....
050
i can insert values to the Customers with UPDATE because i have assigned the default value to be INT 0
the problem is that i need to automate this procedure and to have the customers linked with the products they have already chosen.
because i have only the prod_id as reference key, this causes me trouble to find a way to do the right associations.....
the customers already exist on the customers table...
here are the commands i am using so u can have an idea of what i am trying to do
drop table staff_stud_alloc;
CREATE TABLE allocation
(
prod_id INT UNSIGNED ,
PRIMARY KEY (prod_id),
FOREIGN KEY (prod_id) REFERENCES products (prod_id)
ON DELETE CASCADE
ON UPDATE CASCADE
)ENGINE = InnoDB;
then:
insert into allocation select prod_id from products;
then:
ALTER table allocation ADD cust1 INT DEFAULT 0, ADD cust2 INT DEFAULT 0, ADD cust3 INT DEFAULT 0, .........