473,407 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

modifying relationships using DAO?

Hello,

I have a relationship that I'd like to modify using DAO. Right now the
Cascading updates are off, but I'd like to add them and I'm not sure the
best way to do that.

Any ideas?

Thanks!
Feb 28 '06 #1
5 3843
Rico wrote:
Hello,

I have a relationship that I'd like to modify using DAO. Right now the
Cascading updates are off, but I'd like to add them and I'm not sure the
best way to do that.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

A relationship is really a Foreign Key constraint (FK) between 2 tables.
You can use DDL (Data Definition Language) to define the FK. If the
relationship is already in force you'll have to drop it before you can
assign the new relationship, like this:

ALTER TABLE <foreign key table> DROP CONSTRAINT <constraint name>

If you created the relationship using the Relationship window the
constraint's name will be an internally produced serial number, or a
human readable name. This name is stored in the table
MSysRelationships, column szRelationship.

To create the new constraint use a statement like this:

ALTER TABLE <foreign key table> ADD CONSTRAINT FK_table_name
FOREIGN KEY (<fk column list>)
REFERENCES <primary key table> (<pk column list>)
ON UPDATE CASCADE

The <foreign key table> is the table on the the "many" side of the
relationship. The <primary key table> is the table on the "one" side of
the relationship. The <fk column list> is a comma-separated list of
columns that are in the foreign key table that relate to the <pk column
list> in the primary key table.

An example:

ALTER TABLE OrderDetails ADD CONSTRAINT FK_OrderDetails
FOREIGN KEY (invoice_nbr, order_nbr)
REFERENCES Orders (invoice_nbr, order_nbr)
ON UPDATE CASCADE

The column list for each table must be in the same order. IOW, the
OrderDetails.invoice_nbr relates to the Orders.invoice_nbr and the
OrderDetails.order_nbr relates to the Orders.order_nbr.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRASmKIechKqOuFEgEQKdWQCgpfm8Ekmtsscv/w7DH2VBzWRhQooAn2P0
1hSwVVIRkfZztqWvUMuRb3fO
=sWa9
-----END PGP SIGNATURE-----
Feb 28 '06 #2
TTBOMK one must use an ADODB connection to deal with Updates and
Constraints as in:

(dropping the existing constraint)

CurrentProject.Connection.Execute _
"ALTER TABLE [Order Details] " _
& "DROP CONSTRAINT " _
& "OrderParent "

(and rebuilding it with the OnUpdate or OnCascade attributes set)

CurrentProject.Connection.Execute _
"ALTER TABLE [Order Details] " _
& "ADD CONSTRAINT " _
& "OrderParent " _
& "FOREIGN KEY (OrderID) " _
& "REFERENCES Orders (OrderID) " _
& " ON UPDATE CASCADE " _
& " ON DELETE CASCADE"

Feb 28 '06 #3
You can also use DAO. The DDL statements run just the same as a DAO
QueryDef.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

Lyle Fairfield wrote:
TTBOMK one must use an ADODB connection to deal with Updates and
Constraints as in:

(dropping the existing constraint)

CurrentProject.Connection.Execute _
"ALTER TABLE [Order Details] " _
& "DROP CONSTRAINT " _
& "OrderParent "

(and rebuilding it with the OnUpdate or OnCascade attributes set)

CurrentProject.Connection.Execute _
"ALTER TABLE [Order Details] " _
& "ADD CONSTRAINT " _
& "OrderParent " _
& "FOREIGN KEY (OrderID) " _
& "REFERENCES Orders (OrderID) " _
& " ON UPDATE CASCADE " _
& " ON DELETE CASCADE"

Feb 28 '06 #4
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.

Feb 28 '06 #5
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Didn't know about the Fast Foreign Key. Is that a new feature in
Acc2003? Where is documentation?

In Acc2002, I usually have the ANSI 92 option set. When it is set, the
ALTER TABLE w/ ON UPDATE (or DELETE) CASCADE works thru DAO. That's why
I posted that DAO works w/ my previous posts. Have to take that into
consideration in future.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAUfUYechKqOuFEgEQILlgCfYnRewUabHL/in33O7+B3qNQjhnEAn1EK
mNreQVy3l2lNvqfadsY97r9a
=AbLc
-----END PGP SIGNATURE-----

Lyle Fairfield wrote:
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.

Mar 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: RWC | last post by:
Hi Folks, I should begin by saying I'm fairly new to SQL Server. I'm an application developer who has built front ends atop Server, but have never done much in the way of design / development....
0
by: Megan | last post by:
Hi Everybody- I know that this is a really, really long post, but I wanted to try to give you as much background as possible. So here's a quick overview of the issues I'm asking for help with:...
2
by: Max | last post by:
Hi. I really hope someone can help me. Going slowly insane with this problem. I have a two Access 2000 databases. One is the backend containing tables and some admin queries. The other is the...
7
by: davegb | last post by:
I'm totally new to relational database design. My boss has asked me to create a database of information on the employees in our group. Seemed to me like a simple application to learn the ropes. A...
10
by: Dixie | last post by:
I need to delete some relationships in code. How do I know what the names of those relationships are?
45
by: salad | last post by:
I'm curious about your opinion on setting relationships. When I designed my first app in Access I'd go to Tools/Relationships and set the relationships. Over time I'd go into the window and see...
13
by: ARC | last post by:
Hello all, Prior to going live with my app, I have questions on relationships theory. My prior app was done in Access 97, and I did NOT use relationships at all. I have 65 tables in my...
8
by: Phil Stanton | last post by:
I have a FE, BE database on my home computer and a duplicate on the office computer. Both use Ak2 on Windows XP. The one at home appears normal. The BE consists of about 50 tables with numerous...
4
by: sloney | last post by:
Hello, I have approximately 20 mdb's that have the same schema but all have different data for different geographic locations. There are a plethora of tables and relationships (to be built). I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.