Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Database Design / August 2005

Tip: Looking for answers? Try searching our database.

Delete table relationships?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ben Wallace (3) - 08 Aug 2005 21:08 GMT
Is there a way to determine a table relationship, gather information about
the relationship in order to recreate it later. I'm appending data to some
tables, so I would like to drop the existing relationships, do the append
and then re create the relationships after. Can anyone advise me on trying
to accomplish this. Are there other methods of doing this, if so please
enlighten me.
Gina Whipp - 08 Aug 2005 21:12 GMT
One usually does not have to delete relationships to Append to a table,
maybe you mean to run an Update...  What exactly are you trying to do?

> Is there a way to determine a table relationship, gather information about
> the relationship in order to recreate it later. I'm appending data to some
> tables, so I would like to drop the existing relationships, do the append
> and then re create the relationships after. Can anyone advise me on trying
> to accomplish this. Are there other methods of doing this, if so please
> enlighten me.
peregenem@jetemail.net - 09 Aug 2005 08:51 GMT
> Is there a way to determine a table relationship, gather information about
> the relationship in order to recreate it later. I'm appending data to some
> tables, so I would like to drop the existing relationships, do the append
> and then re create the relationships after. Can anyone advise me on trying
> to accomplish this. Are there other methods of doing this, if so please
> enlighten me.

You can extract schema information, including FOREIGN KEY information
(FK is a stricter interpretation of an Access 'Relationship' because it
must reference a unique key) in various ways. My preference is to use
the OpenSchema method in VBA code because I get a recordset of schema
information and a recordset is a nice flat object to work with (easier
than traversing a hierarchical object model, for example). Here's an
example using my table Payroll in my Airplanes database:

Dim rsKeys As Object
' 27 = adSchemaForeignKeys
Set rsKeys = CurrentProject.Connection.OpenSchema(27, _
     Array(Empty, Empty, Empty, Empty, Empty, "Payroll"))

Here's a peak at the information in the recordset using the Vusual
Basic Editor's Immediate Window:

For Each f in rsKeys.Fields : ?f.Name, f.Value : Next

PK_TABLE_CATALOG            Null
PK_TABLE_SCHEMA             Null
PK_TABLE_NAME Pilots
PK_COLUMN_NAME              pilot_ID
PK_COLUMN_GUID              Null
PK_COLUMN_PROPID            Null
FK_TABLE_CATALOG            Null
FK_TABLE_SCHEMA             Null
FK_TABLE_NAME Payroll
FK_COLUMN_NAME              pilot_ID
FK_COLUMN_GUID              Null
FK_COLUMN_PROPID            Null
ORDINAL       1
UPDATE_RULE   CASCADE
DELETE_RULE   CASCADE
PK_NAME       pk__pilots
FK_NAME       fk__payroll__pilots
DEFERRABILITY Null

If you didn't explicitly choose a name for your schema objects you may
not have names as intelligent (meaningful) as 'pk__pilots', instead you
would have a system-assigned name such as 'Rel_7B67BA8F_D7D7_48B0'.

One thing the FK schema information doesn't reveal, which is required
to recreate the object, is the columns in the PK (PRIMARY KEY) table
['PK' is a bit misleading here because the FK may not be based on a
PRIMARY KEY!] Schema information about PKs and other unique keys may be
extracted using OpenSchema with different parameters. Which leads me to
another point ...

... I have a much easier way of extracting this schema information: I
just look at my SQL DDL (data definition language) script: for my
database:

CREATE TABLE Pilots (
pilot_ID CHAR(10) NOT NULL
CONSTRAINT pk__pilots PRIMARY KEY,
...

CREATE TABLE Payroll (
pilot_ID CHAR(10) NOT NULL
CONSTRAINT fk__payroll__pilots
REFERENCES Pilots (pilot_ID)
ON DELETE CASCADE
ON UPDATE CASCADE,
...

Creating the tables using SQL code means I am in control of what
constraints and indexes are created and I have chosen intelligent names
for them. Re-creating these tables or just the constraints is easy
because it was planned properly.

I agree with the other respondent that it may be best to leave the
constraint (if that's what it is) in place and see which rows fail when
you insert the new data.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.