HomeASP.NET Tables and Relationships for an ASP.NET AJ...
Tables and Relationships for an ASP.NET AJAX Server-Centric Based Online Shopping Website
This is the second part of an eleven-part series focused on building an online shopping web site. In the previous part, we introduced the modules we will use as well as the main flow charts. In this part, we will take a closer look at the database design and describe the table structures and their relationships.
Contributed by Xianzhong Zhu Rating: / 8 December 05, 2007
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 ShoppingDB.mdf, which contains more than tentables. For brevity, we choose to use table form to describe the table structuresof each related table, as follows:
Table 1—Structure for table ‘Role’
Field name
Type
Notes
RoleID
int
Primary Key identifying the record
RoleName
varchar(50)
The name of the role
Table 2—Structure for table ‘Users’
Field name
Type
Notes
UserID
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
Email
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’
Identifying the UserID that places the order. Foreign Key.
OrderFormID
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
NewsID
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
LeavewordID
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
NotifyID
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 fiftystored proceduresto modulate the design of the sample application, which, for brevity, will not be explained any more, but be leveraged in later sections.
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.