today, let's talk about product attributes
We know that different categories of product attributes are different.
We'll build a table prod_class_attr:
Fill in some data for this table:
Next, we'll build a product attribute correspondence table Prod_attr
OK, let's go through the process of adding new items:
The first step is to insert the data into the main product table
Let's create a new stored procedure Sp_new_prod:
BEGIN INSERT into VALUES (_prod_name,_class_id); END
Parameters: in _prod_name varchar (+), in _class_id int
Call for a moment
Call Sp_new_prod (' test product 001',1)
So in the main table, we can see the data we just inserted.
Now we execute the SQL dynamically
OK, let's follow this idea and rewrite just the stored procedure
BEGIN Set @pid=0; INSERT intoProd_main (PROD_NAME,PROD_CLASSID)VALUES(_prod_name,_class_id); Set @pid =last_insert_id (); Set @ss =CONCAT ('INSERT INTO prod_attr Select? As Prod_id,a.* from (', _attr_sql,') A') ; PREPAREPName from @ss; EXECUTEPName using@pid; deallocate PREPAREpname;END
Now this process, we have finished inserting the data at once and adding properties.
previous lesson: MySQL Subversion practical Note (v)--Commodity system Design (II): Regular update of total product hits Copyright Notice: NOTE-taker fugitive pawns love freedom, advocating sharing. But this note stems from the www.jtthink.com (programmer in the awkward way) Judging teacher's "web-level MySQL subversive combat course." For reprint please respect the teacher Labor, retain the judging teacher attribution and course source address.
MySQL Subversion practical note (vi)--Commodity system Design (III): fixed attribute of commodity attribute design