Databases Reference
In-Depth Information
Now notice the difference. The policy table now has one additional column, which adds 4 bytes of storage
requirement. However, the Coverage table has one less column, and has a 62 byte storage requirement.
The previous version required up to 80 bytes of storage. Finally, the Validation table has two fewer
columns and the storage requirements went from up to 35 bytes of storage to 13 bytes.
Figure 8-15
Also, note that the new keys are all fixed length types, not variable length. This means that there is no
need for the 2-byte offset that's required by all the variable length data types. That translates to better
performance and lessens the workload imposed on the server.
Foreign Key Constraints
Recall that the main section is called Data Quality. A fundamental way for enforcing this is through
the use of foreign keys. A foreign key is a column or columns used to link two tables. Preserving the
quality of this link is the job of the foreign key constraint. The classic example of a foreign key is through
Order and OrderDetail tables, as shown in Figure 8-16.
Figure 8-16
CREATE TABLE [OrderDetail](
[OrderDetailID] [int] IDENTITY(1,1) NOT NULL,
[OrderID] [int] NULL DEFAULT(-1),
[ProductID] [int] NOT NULL,
[Quantity] [int] NOT NULL,
[Amount] [smallmoney] NOT NULL,
PRIMARY KEY NONCLUSTERED ([OrderDetailID] ASC)
GO
ALTER TABLE [OrderDetail]
ADD CONSTRAINT [FK_Order_OrderDetail] FOREIGN KEY([OrderID])
REFERENCES [Order] ([OrderID])
GO
Search WWH ::




Custom Search