Databases Reference
In-Depth Information
products with a given name, followed by another request to insert a new record. However,
if you create a UNIQUE KEY constraint for the Products table in the database, the applica-
tion only needs to send a single request to insert the new record and can rely on the data-
base server to verify that the ProductName of the new record is unique. Both
implementations require the same number of logical operations; however, the database
implementation requires fewer server requests, results in less data sent back and forth, and
allows the database server to choose the best way to enforce the uniqueness rule.
Integrating Database Validation in Dynamic Data Applications
Here is a T-SQL script you can use to implement validation of the ProductName unique-
ness at the database level:
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [UK_Products]
UNIQUE (ProductName)
Without additional changes, an attempt to create a new Product with a duplicate name
through the Dynamic Data web application results in a yellow screen of death, as shown
in Figure 9.9.
FIGURE 9.9 Default error page generated for database exceptions.
 
Search WWH ::




Custom Search