Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

i'm making a MySQL data base , my tables are: users, activitylog, activitytype.

to avoid repetitions i thought about including activitytype in each activity which is logged into activitylog table, for example:

1-Activity Types Table

2-Activity Log Table

enter image description here

Is it an interesting model if yes how could i do it ?

share|improve this question
    
How could i do it ? –  Wozniak Mar 9 at 20:22
    
Was my answer correct ? If so marked as ! –  Up_One Mar 10 at 2:25

1 Answer 1

up vote 2 down vote accepted

@Wozniak form what i can see you need the sql syntax t build this structure ! to do so use the syntax belew :

create table Activity_Types(
activity_type_id in,
activity_name varchar(20),
PRIMARY KEY (activity_type_id)
);


create table Activity_Log(
activity_id int,
user_id id,
activity_type_fk id,
activity_date date,
PRIMARY KEY (activity_id),
FOREIGN KEY (activity_type_fk) REFERENCES Activity_Types(activity_type_id)
);

Where foreign key that makes the relation is hold on the Activiy_log table under the activity_type_fk column.
to join this tables just use this columns !

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.