What will be the main key of the "Pictures" table in this example

Table: PhotoAlbum
Columns:
ALBUMID
ALBUMNAME
AlbumDate
AlbumDescription

Table: Pictures
Columns: PictureID
albumid

The problem is that I am using the image id as a link in pic. in an album, so the data is duplicated for each album for that field.

+2


source to share


6 answers


I would say that PictureID is the primary key because it (or should, anyway) be unique for each image. In the end, the definition of a primary key, according to Wikipedia :



In a relational database structure, a unique key or primary key is a candidate key for uniquely identifying each row in a table. A unique key or primary key contains one column or a set of columns. There are no two different rows in a table that can have the same value (or combination of values) in those columns. Depending on its design, a table can have arbitrarily many unique keys, but no more than one primary key.

+9


source


If I'm missing something I think the PictureId will be the primary and the AlbumID will be the foreign key.



+9


source


PictureID, if I don't miss something ...

+5


source


If you want each image to belong to one and only one album, then only the PictureID is ok.

If you want each image to appear in multiple albums, you can make PictureID and AlbumID the combined primary key. That is, the picture is uniquely identified by the combination of the PictureID and the album to which it belongs. Then keep the PictureData in another table (the image would be better described as a PictureAlbum or something)

+1


source


In the first view, pictureId must be the primary key. BUT if I assume there will be a table that will store the Maps information (say PictureMaster) that has PitctureId as the primary key THEN

In the Pictures table, pictureId and AlbumId will create a PrimaryKey (Composite Primary Key) and AlbumId, PictureId will be a ForeignKey.

+1


source


PictureID is the primary key and AlbumID is the foreign key ... PictureID is unique, it does not have the same name, and AlbumID is a group with a unique name.

+1


source







All Articles