简体   繁体   中英

How I nomalize my this database design?

I have two mysql tables named "management" and "services".

"management" table have fields:

- id    
- name    
- designation    
- description    
- added_date

"services" table have fields:

- id    
- name    
- description    
- added_date

Every persons in "management" table should have one image. (their profile image) and in "services" table it will have multiple services and each service should have multiple images.

So my question is, How I get these images to one table named "image_info" and how they separate each other?

UPDATE: This is how I tried it:

# ------------------------
# -- Image Category Table 
# ------------------------

CREATE TABLE IF NOT EXISTS image_category(
    category_id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
    name VARCHAR(60) NOT NULL,  
    PRIMARY KEY (category_id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

# ------------------------------------------
# -- Dumping data for table "image_category"
# ------------------------------------------

INSERT INTO image_category 
                        (name) 
                        VALUES
                        ('service'),
                        ('management'); 

# ------------------------
# Image Table 
# ------------------------

CREATE TABLE IF NOT EXISTS image_info(
    image_id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
    category_id INT(4) NOT NULL, 
    image VARCHAR(80) NOT NULL, 
    image_path VARCHAR(150) NOT NULL, 
    extention VARCHAR(10) NOT NULL, 
    image_size VARCHAR(10) NOT NULL,
    dimension VARCHAR(15) NOT NULL,
    mime_type VARCHAR(20) NOT NULL,
    alt_text TEXT DEFAULT NULL, 
    added_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (image_id),
    UNIQUE (image)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

Hope somebody may help me out.

Thank you.

You could add a column to the management table called profile_image and if not set it would be null . Since this is a 1 to 1 relation. You don't need another table to seperate information that belongs together.

As for the services it is different since they can have multiple images for each service. To handle that add a images table that looks basically like this

images table
------------
id
service_id
name
...

If a service has multiple images, then you would have multiple entries in the images table with the same service_id .

Since the service images and the profile pictures aren't releated in any way, it does not make sense to store them in the same table anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM