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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Identifying and Non-Identifying Relationships

Author  Topic 

Young
Starting Member

2 Posts

Posted - 2003-01-21 : 11:30:06
I have two entities: Album and Song
Each album has a set of tracks (1, 2, 3, etc.). Each track corresponds to a song.

Which of the following is a better data model?

Model#1:
Album: AlbumNum(PK)
Song: AlbumNum(PK,FK), TrackNum(PK)

Model#2:
Album: AlbumNum(PK)
Song: SongNum(PK);AlbumNum(FK) and TrackNum are non-key attributes

Thanks

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2003-01-21 : 12:38:52
CREATE TABLE Artists (Artist VARCHAR(50) NOT NULL PRIMARY KEY CLUSTERED)
CREATE TABLE Albums (Artist VARCHAR(50) NOT NULL REFERENCES Artists(Artist), Album VARCHAR(50) NOT NULL, PRIMARY KEY CLUSTERED (Artist, Album))
CREATE TABLE Songs (Artist VARCHAR(50) NOT NULL, Album VARCHAR(50) NOT NULL, Track TINYINT NOT NULL, Song VARCHAR(50) NOT NULL, FOREIGN KEY (Artist, Album) REFERENCES Albums(Artist, Album), PRIMARY KEY CLUSTERED (Artist, Album, Track), UNIQUE NONCLUSTERED (Artist, Album, Song))

Of course it depends on how the business rules define such things ...

can multiple real world artists have the same name? no
can albums from the same artist have the same name? most likely, not most are remixes
can songs from an album have more than one track of the same track number? no
can songs from an album have more than one song name but on two different tracks? most likely, but lets force songs to have unique names per album

it all depends on the business rules and data that define these entities and the schema you use ... the normalized schema will always be the better (logical) model ...

Go to Top of Page

Young
Starting Member

2 Posts

Posted - 2003-01-21 : 18:24:08
Thanks to Onamuji
Go to Top of Page
   

- Advertisement -