MySQL Subversion practical note (vi)--Commodity system Design (III): fixed attribute of commodity attribute design

Source: Internet
Author: User

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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.