Database relational schema - database

I'm working for a database project that my professor gave to me and now i'm designing the relational schema of database.
I have three entity types album, photo and video that means an album can contain both of them, but I have no idea how to tie them up together.
I'm a beginner in this field so please give me some advice what to do ?

I assume an album can contain several photos and videos. You can create a table joining them. This table can have essentially fours columns: the id of the album, the id of the photo or video, a flag distinguishing whether photo or video, and an index to define the order of the items within an album.
It can of course have an own ID (drawn from a sequence or via autoincrement), a timestamp when it was created, a userid by whom etc.
Can several copies of the same photo belong to an album?

Related

Representing multi-valued attribute in MySQL EER-Diagram

I need help with a project for my university programme. The task is to design a database using MySQL and creating ER- and EER-Diagrams for it. The database I want to create is my music library.
My main entities will be Song, Artist, Album and Publisher. Since one Song can have multiple arists, how do I represent that in my design/diagram? My understanding is that that attribute can usually have only a single value.
I hope you can help me with this.
ERD Solution
So you actually have a many-to-many relationship because a song can be sung by many artist and an artist can sing many songs. Therefore, you need a junction table to represent a many-to-many relationship in an ERD.

Should i make seperate tables for each album?

I'm working on a database project about music and albums in MySQL, where i make a list over some popular artists, their most sold album, and the songs contained within them. But i suddenly got really uncertain of what to do when it comes to filling in the name of the songs for each album. Should i make an individual table for each list of songs, or should all the songs (about 50 of them in total from all the albums) from all the different artists (5 different artists) be filled inn in the same table (i'm eventually gonna export the data and connect it to a PHP folder
Hope the question was clear
All the songs should be in one "Songs" table. Then you create a column "Album ID" in that table which is a foreign key back to the ID column in the albums table. This is how you know which song belongs to which album. (And of course you have the same kind of relationship between "album" and "artist".)
This is called a "one-to-many" relationship and is one of the basic principles of relational database design.
If you ever find yourself creating multiple tables to represent the same kind of data item, you know you've gone wrong.
N.B. If you want to support the idea that the same song (or track probably, to be more accurate, since many different recordings of a song could potentially be made) can be included on multiple albums, then you'll need to implement a "many-to-many" relationship where you have an extra table in between "albums" and "songs" which holds Album ID and Song ID. Each would be a foreign key back to the Albums and Songs tables, respectively. And to ensure no duplication, both fields would be specified as a Compound Primary Key. That way you can list the same Song ID in that table many times against different albums. Same again if you want to have that flexibility in the relationship between "artists" and "albums".
This might be a good time to take a break and study relational database design and data normalisation concepts in some more detail, then you can start to see these patterns for yourself and make the right decision in your schema designs.
Similarly to this question about databases for playlists you should also use one table for the albums and one table for the songs.
Additionally you might also need a table for artists, etc.

Creating a database schema from The Movie Database

I'm trying to create a database schema using information pulled from the themoviedb api.
I thought I was doing ok until I went to add in the television series, then I got really confused.
The TMDb API seems to treat television series and movies as completely separate things. It further divides television listings into series, seasons, and episodes.
For example there is a separate cast listing for television seasons (season regulars) and individual episodes (guest cast). I have no idea how to reflect all this in the database.
I've tried my best to model everything below, but I think there's something wrong somewhere. Please ignore the datatypes.
Role can be either writer, director, or actor.
http://imgur.com/a/1WKQB
Hi user2146821,
Your database design looks good, with the exception of how to display the relations between regular cast and guest cast members, as you've expressed.
Currently, you are approaching the scenario by having a singular join table between Movie, TV Seasons, TV Episodes and Person. This creates a table for which you cannot have either a singular primary key nor a correct composite primary key, as you will have nulls for any given record.
In the linked image above, you can see another way of handling this relationship - you create three join tables, each with Person on one side and a corresponding table on the other (either Movie, TV Season or TV Episode). This eliminates nulls from the join tables, allows for composite primary keys to be formed in the joins tables and structures the database in a more meaningful way.

Denormalization of database tables for Lucene indexing

I am just starting up with Lucene, and I'm trying to index a database so I can perform searches on the content. There are 3 tables that I am interested in indexing:
1. Image table - this is a table where each entry represents an image. Each image has an unique ID and some other info (title, description, etc).
2. People table - this is a table where each entry represent a person. Each person has a unique ID and other info like (name, address, company, etc)
3. Credited table - this table has 3 fields (image, person, and credit type). It's purpose is to associate some people to a image as the credits for that image. Each image can have multiple credited people (there's the director, photographer, props artist, etc). Also, a person is credited in multiple images.
I'm trying to index these tables so I can perform some searching using Lucene but as I've read, I need to flatten the structure.
The first solution the came to me would be to create Lucene documents for each combination of Image/Credited Person. I'm afraid this will create a lot of duplicate content in the index (all the details of an image/person would have to be duplicated in each Document for each person that worked on the image).
Is there anybody experienced with Lucene that can help me with this? I know there is no generic solution to denormalization, that is why I provided a more specific example.
Thank you, and I will gladly provide more info on the database is anybody needs
PS: Unfortunately, there is no way for me to change the structure of the database (it belongs to the client). I have to work with what I have.
You could create a Document for each person with all the associated images' descriptions concatenated (either appended to the person info or in a separate Field).
Or, you could create a minimal Document for each person, create a Document for each image, puts the creators' names and credit info in a separate field of the image Document and link them by putting the person ID (or person Document id) a third, non-indexed field. (Lucene is geared toward flat document indexing, not relational data, but relations can be defined manually.)
This is really a matter of what you want to search for, images or persons, and whether each contains enough keywords for search to function. Try several options, see if they work well enough and don't exceed the available space.
The credit table will probably not be a good candidate for Document construction, though.

One table for uploads for multiple resources in CakePHP

I have CakePHP app in which I'd like to attach gallery to multiple resources. Let's say I've got artists, each one has own gallery. I've got articles, every article has some images attached to it and so on. Now I set up tables like this:
Artists hasMany Artistimages, fields in artistimages table are: id, artist_id, filename, filetype, filesize etc.
Articles hasMany Articleimages, fields in articleimages table are: id, article_id, filename, filetype, filesize etc.
...but this is not how it should be, I think.
Is there possibility to have one table called for example uploads which will contain all images with foreign key pointing to resource its reffering to? How to tell CakePHP which image is coming from which resource?
I'd recommend using the Polymorphic Behavior. I often do this for a Binary model which covers images, documents, etc. These represent the physical files that can be associated with any number of models (photos, applicants, etc.).
The gist of a polymorphic relationship is that the table has 2 additional fields. One field that indicates the name of the model being associated (e.g. Photo, Applicant, etc.) and another for the foreign key value (i.e. the id field in the photos table, for example).
If this was me, I would have an images table, then I would have the Artist and Article hasAndBelongsToMany to Image.
Your HABTM would then have a two join tables artists_images and articles_images, then with any luck, Cake will write into these join tables the relationships between each. So you should end up with the correct things associated with the correct images.
By using the HABTM, you can even have one image associated with an Article and Artist, and the same image associated more than once if you need to.
Hope this makes sense, there is more info on HABTM in the book, http://book.cakephp.org/view/83/hasAndBelongsToMany-HABTM
For all of you looking for working solution using polymorphic behavior and MeioUpload, check out this. I'm using it right now and it seems to work fine.

Resources