Petshop 4 Database Analysis 1

Source: Internet
Author: User
Although there are a lot of learning materials for petshop in the garden, especially the series of anatomy petshop written by Teacher Zhang Yi in my learning materials, it is quite exciting, this is a relatively complete example.. NET Framework, technology, and related design patterns. I wrote this article not to mention how profound I have understood the entire framework. To be honest, I have just come into contact with it. net is a beginner. I just want to write down what I have learned. If you see something written by someone else, it means that I have understood that degree. If something is not involved or too rough, it means that I have not understood it deeply. This is my Technology Article For more information.
Before that, I want to make a summary of my learning process. In the past, when I was not in touch with the design pattern, I always thought that object-oriented is to encapsulate data and methods, after I encapsulate it, it means that I have already become object-oriented. I learned. After net, I think that layering means separating the sequence layers, data access, and business processes. Each layer calls the method of the next layer, this structure is layered. To be honest, this question has been confusing for a long time. Why does my Code It's always not so elegant. Why? Every time I change a lot of things. I remember a teacher once told me that you encapsulate them, and they are the same as they are not encapsulated. There is no difference, but the location of the Code has changed, at the beginning, I never understood why my position has changed. What kind of structure is a good structure, and how to design my code is good. Today, I saw petshop. My feeling tells me that his design is better than mine. No matter what the advantages and disadvantages are, my idea is to first absorb the advantages.
To put it bluntly, I will first learn the entire petshop structure from the database in my understanding.
In general, petshop divides the database into four databases. From a functional point of view, it is good to separate the database. In terms of functionality, A single function is achieved at the database level, and orders with a large amount of data are separated.
1. mspetshop4.
This database mainly manages products. There are six tables in this database. As shown in:

Aspnet_sqlcachetablesforchangenotification is used for caching. We will discuss this later.
The product category table of the category table. This category mainly classifies products in large categories, such as fish and birds in petshop. I think you can understand the meaning of the fields. One is the category ID, the other is the category name, the other is its description, and the primary key is the category ID.
The product table is a product table. This product is not a final product, but an abstract product, such as fish and many types of fish, such as sharks. For a pet store, sharks have several different names, so there are several different names on the shelf. Each name must be represented in the item table. In the product table, its fields are: Product ID, product category, product name, remarks, and image addresses corresponding to such products. In this table, four indexes are created with the product ID as the primary key: 1. product Name; 2. category id; 3. product Name + category ID; 4. product ID + product name + category ID. For more information about indexes, see database information.
The item table is a specific pet. Each product corresponds to one or more specific items. In this table, productid is the product corresponding to it, and a foreign key constraint is created on this field. The fields in this table are the pet item ID, corresponding product ID, pet price, and unitcost. I have not figured out what it means. Supplier ID, status (I only see the data in it as P, but I don't know how to modify it), pet name, and the image address corresponding to the pet. In this table, Itemid is the primary key, productid and supplier are the foreign keys, that is, their values are values in the product table and supplier table, and a large index is created: itemid + productid + listprice + name.
The supplier table is a supplier table. I haven't seen much about the role of this table, but here I will identify who the supplier of each PET is. After the standard petshop is installed, there are only two pieces of data in it, now let me introduce the meaning of the fields in this table. The primary key is the supplier ID. The following are the supplier names, and the value in status is AC. I don't know what it means. addr1, addr2 must be clear at first glance. The city can also be clear from the literal meaning. The State represents which state in the United States and zip code is used, the phone number is next to it.
Inventory is a pet inventory table. Itemid is the pet ID, and the number of inventory is shown below. I personally think that the Itemid here should be a foreign key constraint, but petshop does not. I don't know why.
According to the above database table, petshop abstracts several data entity classes. Let's analyze it first. There are a total of six tables in the above database, which can represent the following concepts: cache, category, and product (I don't know if this is a good idea ), pet information, suppliers, inventory. The cache can be used as a data entity. Because the cache is only a technology, the inventory is an attribute that can be included in the pet information. I think, the rest can be abstracted or mapped. However, in petshop, only the categories, products, and pet information are abstract entities without specific supplier classes. The reason may be that in petshop, suppliers are not a major contradiction, that is to say, the pet store does not have much to do with the supplier, so it is not included. Let's take a look Program Is how to abstract. As shown in:

As you can see, the classes in are basically an abstraction of the tables in the database. Besides iteminfo, several fields are added. In this figure, I use the class chart generated by vs. They correspond to the model project in petshop. In this project, they not only abstract the tables in the database, but also like orders, order items, etc. We will detail the analysis to other databases. The model project mainly abstracts data entities. It provides a database abstraction for the business layer and data access layer. We can simply think of it as a ing between entities. It is mainly used to convert the database record into objects in the object-oriented model and provide strong data access.
Let's write it here today. In the following articles, I will analyze other databases. Maybe this does not show the entire petshop structure, but I want to pull up from the bottom layer until we can look at such a big design idea from a high angle.

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.