A downloadable .rar file is available for this article.
Database Design
With the modules and main flow charts introduced , now we are ready to shift our attention to the database design.
Tables Design
In this article, we’ll design a database named S hopping DB.mdf , which contains more than ten tables . For brevity, we choose to use table form to describe the table structures of each related table, as follows:
Table 1—Structure for table ‘Role’
Field name |
Type |
Notes |
RoleID |
int |
Primary Key identifying the record |
Role Name |
varchar(50) |
The name of the role |
Table 2—Structure for table ‘Users’
Field name |
Type |
Notes |
User ID |
int |
Primary Key identifying the record |
UserName |
varchar(50) |
The registering name of the user |
RealName |
varchar(50) |
The real name of the registered user |
Password |
varchar(255) |
The password of the registered user |
Address |
varchar(200) |
The address of the user |
Phone |
varchar(20) |
Phone number of the user |
Mobile |
varchar(20) |
The mobile number of the user |
|
varchar(200) |
The email address of the user |
CreateDate |
datetime |
Date and time when the user registers |
Status |
bit |
Identifies the current status of the user |
RoleID |
int |
Foreign key, referring to field RoleID in table ‘Role’ |
Remark |
text |
Other info of the user |
Table 3 —Structure for table ‘Category’
Field name |
Type |
Notes |
Category ID |
int |
Primary Key identifying the record |
Desn |
varchar(200) |
The category name |
ParentID |
int |
The ID value of the parent category |
OrderBy |
int |
The order number when in sort |
Remark |
text |
Memo info |
{mospagebreak title=Tables continued}
Table 4 —Structure for table ‘Product’
Field name |
Type |
Notes |
ProductID |
int |
Primary Key identifying the record |
Name |
varchar(200) |
The product name |
CategoryID |
int |
Foreign Key, referring to the Category ID that the product belongs to |
Desn |
text |
Detailed description for the product |
Sell |
varchar(200) |
The name of the supplier |
CreateDate |
datetime |
Manufacturing datetime |
SellInDate |
datetime |
Stock datetime |
Unit |
varchar(50) |
|
Quantity |
int |
Current quantity of this kind of product |
Upper |
int |
The maximum stock quantity of this kind of product |
Lower |
int |
The minimum stock quantity of this kind of product |
InPrice |
money |
Stock price |
OutPrice |
money |
Sale price |
PictureID |
int |
Identifying the related Picture ID of the product. Foreign Key. |
Remark |
text |
Memo info for the product |
Table 5 —Structure for table ‘Pictures’
Field name |
Type |
Notes |
Picture ID |
int |
Primary Key identifying the record |
Desn |
varchar(200) |
The name of the image/picture |
Type |
varchar(200) |
The type of the image/picture |
Data |
image |
The factual data about the image/picture |
Table 6 —Structure for table ‘Comment’
Field name |
Type |
Notes |
Comment ID |
int |
Primary Key identifying the record |
Desn |
varchar(200) |
Title of the comment |
Body |
varchar(200) |
The detailed content of the comment |
Dat e |
image |
The time the comment was created |
ProductID |
int |
Identifying the Product ID that the comment belongs to. Foreign Key. |
UserID |
int |
Identifying the User ID that makes the comment. Foreign Key. |
Table 7 —Structure for table ‘OrderForm’
Field name |
Type |
Notes |
Order Form ID |
int |
Primary Key identifying the record |
UserID |
int |
Identifying the UserID that places the order. Foreign Key. |
TotalNumber |
int |
The total number of the product to buy |
TotalMoney |
money |
The total fee of the product to buy |
OrderDate |
datetime |
The datetime when the order is placed |
State |
int |
Identifying the status of the order |
{mospagebreak title=More Tables continued}
Table 8 —Structure for table ‘OrderItem’
Field name |
Type |
Notes |
OrderItem ID |
int |
Primary Key identifying the record |
Product ID |
int |
Identifying the UserID that places the order. Foreign Key. |
OrderForm ID |
int |
The total number of the product to buy |
Number |
int |
The total fee of the product to buy |
Table 9 —Structure for table ‘News’
Field name |
Type |
Notes |
News ID |
int |
Primary Key identifying the record |
Desn |
Varchar(200) |
Identifying the title of the news |
Body |
text |
The detailed content of the news |
Date |
datetime |
The date and time the news was created |
UserID |
int |
Foreign Key that refers to the field UserID in table ‘User’ |
Table 10 —Structure for table ‘Leaveword’
Field name |
Type |
Notes |
Leaveword ID |
int |
Primary Key identifying the record |
Desn |
Varchar(200) |
Identifying the title of the left word |
Body |
text |
The detailed content of the left word |
Date |
datetime |
The date and time the left word was created |
UserID |
int |
Foreign Key that refers to the field UserID in table ‘User’ |
Table 11 —Structure for table ‘Notify’
Field name |
Type |
Notes |
Notify ID |
int |
Primary Key identifying the record |
Desn |
Varchar(200) |
Identifying the title of notification |
Body |
text |
The detailed content of the notification |
Date |
datetime |
The date and time the notification was created |
Besides these tables, we’ve also defined more than fifty stored procedures to modulate the design of the sample application, which, for brevity, will not be explained any more, but be leveraged in later sections.
{mospagebreak title=Relationships Between Tables}
Set up the Relationships Between the Tables
Next, let’s continue to take a look at the dependency relationships between the above defined tables. Readers that are familiar with the famous "Northwind" database should quickly realize that the relations between tables here are pretty similar to those and easy to follow. The following Figure 5 gives the dependency relationships between the tables.
Figure 5—the dependency relationships between the tables in database ‘ShoppingDB’
Author’s Note: during the course of studying the sample application, you can use Visual Studio 2005 (I cannot open the above chart in it) or Microsoft SQL Server Management Studio to open the relation chart. The latter requires that you first close the connection with the database in VS2005, then start up Microsoft SQL Server Management Studio and attach the ShoppingDB.mdb database to it. Next, you can right-click the database, open the "property" window and switch to the "options" tab to change the "compatibility level" to "SQL Server 2005 (90)." Finally, you can get to the above relation chart by double clicking the "database relation chart" node. By the way, to reopen the database in VS2005 you have to detach it from Microsoft SQL Server Management Studio first, or else you will meet with some error.
Here there is only one point for us to remember. It is that the relations set up in the above Figure 5 must be followed in later programming to keep the related data in tables integrated and valid.
The post Tables and Relationships for an ASP.NET AJAX Server-Centric Based Online Shopping Website appeared first on ASP Free.