Database Design Composite Keys?

I would stay away from composite keys. The surrogate key issue is up for debate, but I always use an INT Identity column (in SQL Server) if I can get away with it. I only use GUIDS if the database must support replication or merging distributed data I think your columns look OK other than the GUIDs.

I would stay away from composite keys. The surrogate key issue is up for debate, but I always use an INT Identity column (in SQL Server) if I can get away with it. I only use GUIDS if the database must support replication or merging distributed data.

I think your columns look OK other than the GUIDs.

You would only need a composite key on columns 0 and 1 of ContactInformation if each contact could belong to more than one headquarter; since you need the opposite, what you've descrbed should work fine. Personally I would only use Guids if I really really needed to. Stick to ints otherwise.

I also tend to use surrogate keys nearly everywhere.

I would say that your primary key should be Id. A composite key on ContactInformation of Id and HeadquarterID might make sense if you will use those two pieces of information often together, but I'd prefer using just Id as a key and then you can create an index on Id and HeadquarterID if you really need to.

As well as the surrogate key (your GUID Id) it is often a good idea to identify a business key (natural key/domain key) that is based on the business attributes that define the entity. With the present table design, there is nothing stopping you adding two contact with the same attributes (name, headquater, address etc..). This is usually not desirable,so you add a composite natural key on the attributes that define the contact.As a PK is already defined, the Inatural key will be a unique constraint/index on those attributes.

I agree that the PK should be simple rather than composite. Composite PKs are a real pain to work with and queries become more complex.

It's a mistake to imagine this is a choice between using a composite key OR a surrogate. A surrogate key achieves something quite different from a key constraint on other attributes. The surrogate does not prevent those attibute values from being duplicated so the meaning of the table would be quite different if you just used one or the other key.

You should implement whatever keys you need to ensure the uniqueness and integrity of the data. If that means using a composite key as well as a surrogate then do so. Having said that, it isn't clear to me what the likely keys are in your example.

If Id is a candidate key of ContactInformation then (HeadquarterId, Id) is not - it's a superkey but it's not irreducible.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions