Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Zajcica
Starting Member
22 Posts |
Posted - 2013-04-24 : 11:16:16
|
Please, I dont understand why weak entity cannot have a key ateribute!If we have, f,e, , an example: a room can not exist without a building, but one building can have 0 to many rooms, does it mean that a room as a weak E cannot have key attribute?Can U give me an example?Many thanks! |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2013-04-24 : 12:01:08
|
I'm not sure if this is a strong example, but I think this is considered a Weak Entity..Consider an order system. In many systems you have an Order (Header) and an Order Detail (or Line Item). The Order Detail doesn't make any sense without the Order itself. So the Order Detail (or Line Item) would be considered a Weak Entity becuase it needs the Order (Header) to (FK to Order) exist in order for you to have an Order Detail (Line Item) row.Honestly, I wouldn't get hung up in classifications of entities. Just know there are Enties, Attributes and Relationships. Master that, and you'll do fine. |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-04-24 : 12:40:47
|
I agree with Lamprey; it is all relative depending on how you design your data model.For an attribute to be a key, it should be uniquely identifiable.Here is another example, if you want to create a table containing information about your friends. You may create a table like this:[CODE]CREATE TABLE dbo.Friends (Name NVARCHAR(20),Birthday Date,CellPhone NVARCHAR(20),);With the following data:Name Birthday CellPhoneJohn Jan 2, 1996 1234566-0989Phil Aug 1, 1994 John Jun 1, 1995 1222566-0989Andrew Aug 1, 1994 1234566-0988[/CODE]Since two friends have the same name, and two of them have the same birthday you cannot use either name or birthday as keys. Since Phil does not have a Cellphone you cannot use CellPhone as a key either. In this case you can do couple of things to create a key; You can combine Name, birthday and Cellphone together as a key, because it is unlikely that two friends will have the same name, birthday and cellphone number; together they should form a unique identifier. Or you may choose to add a new attribute to the table called ID and assign a unique number for each of your friends. [CODE]CREATE TABLE dbo.Friends (Name NVARCHAR(20),Birthday Date,CellPhone NVARCHAR(20),ID int);Name Birthday CellPhone IDJohn Jan 2, 1996 1234566-0989 1Phil Aug 1, 1994 2John Jun 1, 1995 1222566-0989 3Andrew Aug 1, 1994 1234566-0988 4[/CODE]You can read more on this topic at:http://en.wikipedia.org/wiki/Weak_entityhttp://en.wikipedia.org/wiki/Relational_databasegood luck |
|
|
|
|
|
|
|