We help IT Professionals succeed at work.

three  questions actually

ymasri asked

I'm trying to create a relationship between two tables using the SQL Server Enterprise Manager.  To do this, I followed the documentation; expanded my database --> Diagrams -right click-> New Database Diagram --> and I followed the wizard.  When I finished, I had a white space area with nothing on it(despite I think there should be the two tables I chose to include in the diagram - nevertheless), and when I clicked on the add table icon but the following message appeared:
"CoInitialize has not been called"! Do anybody of you know anything at all about what this message is talking about?

Is it possible to have two foreign keys in the same table pointing to a primary key in another table? For example, I have table called USERS, and another called ADDRESSES, the ADDRESSES table can be explained as billing or shipping addresses, so the USERS table may have shippingid and billingid fields pointing to addressid field in the ADDRESSES table.

This may look very primitive, but I really need an answer. What do we need the primary key - foreign key relationship for? Can't we just retieve the records from tables without this relation?

Watch Question

For Q:3

Unless u have a (PrimaryKey-foreignKey) relation, finding the dependencies in a medium sized database will be difficult..

Q2 yes

Q3 No need for them - they are for protection of the integrity of the database.
If I have control of a database I never put on any primary or foreign keys as all access is controlled via SPs and if I make manual changes I check the relationships via scripts. If you have many people working on a database or have uncontrolled client access then constraints protect against coding bugs.


Thank you guys for your response. Nigelrivett, as per the second question, and after I failed to create the relation using the EM, I used the SQL Query Analyzer to create it: "alter table users add constraint fk_addressid foreign key(shippingid,billingid) references addresses(addressid,addressid)", but the checker objected saying that: "Duplicate columns specified in FOREIGN KEY constraint key list, table 'users'". So if you think it could be done, can tell me how?
As for the second question, what do you think of what SoundararajanVenkat has said?
Thank you again
you need

alter table users add constraint
fk_shippingid foreign key(shippingid) references addresses(addressid)
alter table users add constraint
fk_billingid foreign key(billingid) references addresses(addressid)

This is two constraints not one.
As for finding dependencies I get them from the checking script or documentation - but mostly should be obvious from naming conventions.


Thank you for the follow up.  So what you are saying is that I can apply those two constrains together on the same table? It came to me that when you right click a table and select properties in the design window then press the 'relationships' tab, you're prompted to choose among the relationships (constrains) you created one at a time to apply it on that table.  Do you have anything to say about that?
I never use the gui as I want to keep the scripts in SourceSafe as a record of what I have done and to have a database creation script.
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
Top Expert 2004


No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Nigelrivett's comment

Please leave any comments here within the next seven days.


EE Cleanup Volunteer

Explore More ContentExplore courses, solutions, and other research materials related to this topic.