- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
The Relational Model in C#
3 Make QR Code JIS X 0510 In C# Using Barcode creator for VS .NET Control to generate, create Denso QR Bar Code image in .NET framework applications. www.OnBarcode.comQR Code JIS X 0510 Scanner In C#.NET Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comThe Relational Model
Barcode Generator In Visual C# Using Barcode drawer for .NET framework Control to generate, create bar code image in .NET applications. www.OnBarcode.comRecognize Bar Code In Visual C#.NET Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comFirst Normal Form
QR Code 2d Barcode Drawer In .NET Framework Using Barcode generator for ASP.NET Control to generate, create QR Code image in ASP.NET applications. www.OnBarcode.comQR Creator In VS .NET Using Barcode encoder for Visual Studio .NET Control to generate, create Denso QR Bar Code image in .NET applications. www.OnBarcode.comImagine a real-world scenario with customers that order products. Customers, orders, and products are entities you discovered when you got the description of the business scenario. Initially, you model everything in a single table called Orders. Table 3-1 shows an imaginary Orders table. Columns that are part of the key are shaded (OrderId only in this example). Printing QR Code In VB.NET Using Barcode creator for Visual Studio .NET Control to generate, create QR image in Visual Studio .NET applications. www.OnBarcode.comBar Code Creation In C# Using Barcode printer for .NET Control to generate, create barcode image in .NET applications. www.OnBarcode.comTABLE 3-1 1D Drawer In C# Using Barcode creation for .NET framework Control to generate, create Linear Barcode image in VS .NET applications. www.OnBarcode.comCreate Code 128A In Visual C# Using Barcode drawer for .NET framework Control to generate, create ANSI/AIM Code 128 image in .NET applications. www.OnBarcode.comA Table Before 1NF
ANSI/AIM Code 39 Drawer In C# Using Barcode maker for VS .NET Control to generate, create Code 39 Extended image in VS .NET applications. www.OnBarcode.comPrinting UPC-E Supplement 5 In C# Using Barcode creation for .NET framework Control to generate, create UPC-E Supplement 5 image in .NET framework applications. www.OnBarcode.comCustomerId
DataMatrix Generator In VB.NET Using Barcode encoder for VS .NET Control to generate, create Data Matrix image in .NET applications. www.OnBarcode.comRecognize Code 3 Of 9 In Java Using Barcode decoder for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.com1 1 2 Printing PDF 417 In None Using Barcode encoder for Microsoft Word Control to generate, create PDF 417 image in Microsoft Word applications. www.OnBarcode.comCode-128 Generation In Java Using Barcode encoder for BIRT Control to generate, create Code 128 Code Set C image in BIRT reports applications. www.OnBarcode.comOrderId
USS-128 Creation In Java Using Barcode drawer for Java Control to generate, create GS1-128 image in Java applications. www.OnBarcode.comEAN / UCC - 14 Scanner In C#.NET Using Barcode recognizer for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.com1 2 3 Encode Matrix Barcode In .NET Using Barcode creation for ASP.NET Control to generate, create Matrix 2D Barcode image in ASP.NET applications. www.OnBarcode.comCreate GS1-128 In None Using Barcode creator for Font Control to generate, create USS-128 image in Font applications. www.OnBarcode.comCustomerName
Company ABC Company ABC Company ABC
OrderDate
2008-10-22 2008-10-24 2008-09-15 Items
Ap Apples q=5, Ch Cherries q=10 Ba Bananas q=12 Ap Apples q=3, Ba Bananas q=3
This design is, of course, problematic. Some possible data manipulation anomalies are the following: Insert
How do you insert a customer without an order (By the way, can you see the incompleteness problem ) Update
If item Ba is renamed, how do you perform an update You can easily miss some row you should update. This occurs because of redundancy. Delete
If order 3 is deleted, the data for customer 2 is lost. This is also a problem of incompleteness.
Select
How do you calculate the total quantity of bananas This is the problem with a nonscalar column. The Items column is a collection. The rst normal form (1NF) says that a table is in rst normal form if all columns are atomic. No multivalued columns are allowed. Note that the 1NF de nition simply states that a table must represent a relation. Decomposition has to start with the Items column. You need a single row per item in an order, and every atomic piece of data of a single item (ProductId, ProductName, Quantity) must get its own column. However, after the decomposition, you get multiple rows for a single order. OrderId by itself cannot be the key anymore. The new key is composed of the OrderId and ProductId columns. If you allow multiple products on a single order for example, each time with a different discount you would not be able to use the ProductId as a part of the key. You would probably add ItemId attribute and use it as a part of the new key. A decomposed table in 1NF would look like Table 3-2. Inside Microsoft SQL Server 2008: T-SQL Querying
TABLE 3-2 A Table in 1NF
Product ItemID ProductId Quantity Name
1 2 1 1 2 Ap Ch Ba Ap Ba 5 10 12 3 3 Apples Cherries Bananas Apples Bananas
OrderId CustomerId CustomerName OrderDate
1 1 2 3 3 1 1 1 2 2 Company ABC Company ABC Company ABC XYZ XYZ 2008-10-22 2008-10-22 2008-10-24 2008-09-15 2008-09-15 Before I start with 2NF, let me point out one common misconception with 1NF. You ll often read about repeating group of columns. Take, for example, the Employees table design shown in Figure 3-11. Employees PK EmployeeId EmployeeName Child1Name Child2Name Child3Name
FIGURE 3-11 The Employees table
You probably feel uncomfortable with this table. It has a repeating group of columns with a similar name ChildXName. Child1Name means the name of the oldest child, Child2Name means the name of the second oldest, and Child3Name means the name of the third oldest (disregarding twins). Of course, the question is, what if an employee has more than three children You d probably create a new table. You might think that you are normalizing the Employees table. You know that the relational model does not depend on names. Let s rename the table and all of the columns and get a table shown in Figure 3-12. Orders PK OrdersId CustomerID OrderDate DueDate ShipDate
FIGURE 3-12 The Orders table (the Employees table renamed) You probably feel more comfortable with this design, and this table seems perfectly normalized. The Employees table was in 1NF as well, but the problem is that a constraint is built into both tables. The rst constraint says we have employees with three (or at most three if the columns allow NULLs) children; the second constraint says an order has three 3
The Relational Model
dates. Of course, the rst constraint makes no sense in real world, and the rst design was bad anyway. However, it was normalized. Remember that you can constrain with the data model itself with table design. Often a repeating group of columns with similar names really represents a hidden collection; however, don t decompose such groups automatically. Check the business rules the constrained predicates rst.
|
|