Re: modifying relationships using DAO?
- From: "Lyle Fairfield" <lylefairfield@xxxxxxx>
- Date: 28 Feb 2006 13:11:14 -0800
In Access 2003 this
DBEngine(0)(0).Execute _
"ALTER TABLE [Order Details] " _
& "ADD CONSTRAINT " _
& "OrderParent " _
& "FOREIGN KEY (OrderID) " _
& "REFERENCES Orders (OrderID) " _
& " ON UPDATE CASCADE " _
& " ON DELETE CASCADE"
gives me a Syntax Error in the Constraint Clause.
I note this:
Foreign keys
When dealing with foreign keys, the concept of a fast foreign key may
be useful. A fast foreign key is a foreign key that has no index.
Although this may seem counter-intuitive, there is a valid explanation
for it. By default, when a foreign key is defined, an index based on
the column(s) in the foreign key is created automatically. In many
instances this enhances performance when executing operations that
maintain referential integrity. However, if there are many duplicated
values in the foreign key field, the foreign key index will affect
performance when records are added and deleted from the table. To
prevent the automatic creation of indexes on foreign keys, use the NO
INDEX keywords in the declaration of the foreign key.
ALTER TABLE tblInvoices
ADD CONSTRAINT FK_tblInvoices
FOREIGN KEY NO INDEX (CustomerID) REFERENCES
tblCustomers (CustomerID)
ON UPDATE CASCADE
ON DELETE CASCADE
Note The fast foreign key statement can only be executed through
the Jet OLE DB provider and ADO. It will return an error message if
used through the Access SQL View user interface. Also note that to drop
a fast foreign key, you must issue the DROP CONSTRAINT statement
through the Jet OLE DB provider and ADO.
Another example of a situation where a fast foreign key would be useful
is in an order entry database application. Assume that there is a table
called CustomerTypes that identifies what type of customers are being
tracked, a Customer table, and an Orders table. Assume that there are
10 rows in the CustomerTypes table, 100,000 rows in the Customer table,
and 350,000 rows in the Orders table. A good choice for the Customers
table would be a fast foreign key that references the primary key in
the CustomerTypes table. This is because there is a maximum of 10
unique values out of 100,000 rows. An index here has little value for
retrieving data and would be a drag on concurrency and inserts,
deletions, and updates in the CustomerType column.
On the other hand, the fast foreign key would probably not be useful
when applied to the CustomerID column in the Orders table, because
those values are likely to be unique, since each represents a different
customer. In this instance having the foreign key indexed in the
regular manner is very advantageous because it is used in joins and
other lookup criteria.
---
As ADO always works, I always use it.
.
- References:
- Re: modifying relationships using DAO?
- From: Lyle Fairfield
- Re: modifying relationships using DAO?
- From: MGFoster
- Re: modifying relationships using DAO?
- Prev by Date: Re: Importing multiple files..
- Previous by thread: Re: modifying relationships using DAO?
- Next by thread: Importing multiple files..
- Index(es):
Relevant Pages
|