php - MySQL InnoDB AUTO_INCREMENT secondary column -


i making system users can upload file want, , not use execute kind of code. part of that, rename every file, , store original name in mysql table. table contains id of user uploaded it, , unique id of upload. doing this:

create table `uploads` (     `user_id` int(11) not null,     `upload_id` int(11) not null auto_increment,     `original_name` varchar(30) not null,     `mime_type` varchar(30) not null,     `name` varchar(50) not null,     primary key (`user_id`, `upload_id`) ) engine=myisam; 

this means have unique combination of user_id , upload_id, , every users first upload has id of 1. want use foreign key user_id, if delete user, uploads deleted. means have in innodb. how go that, since above setup works in myisam.

my users table (wich user_id from) looks this:

    create table `".database."`.`users` (     `user_id` int not null auto_increment primary key,     `username` varchar(30) not null,     `email` varchar(50) not null,     `password` char(128) not null,     `salt` char(128) not null  ) engine = innodb; 

what want uploads table this:

user_id  | upload_id 1        | 1 1        | 2 2        | 1 2        | 2 2        | 3 1        | 3 

if makes sense

if understood correctly:

replace primary key unique index 2 fields. make upload_id primary key , user_id foreign key then.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -