I'm currently working on a college project and I'm having a bit of trouble figuring my db structure out.
I have a table "users" that stores the user account data(username, password, email). Each user would have several tables associated with it, and also, data rows in various other tables.
Since each user could have several tables associated with it, i want to store the name of the tables and the name of a user, in a separate table.
I have something like:
users
userdata:Code:+-----------+------------+-- | Id(int,pk)| user |....etc +-----------+------------+----- | x | user1 | +-----------+----------- +---- | y | user2 | +-----------+----------- +---- . . .
However, when I try to insert values like this in my usersdata table, I getCode:+-----------+---------+-----------+ | Id(int,pk)| userid |tablename |....etc +-----------+---------+-----------+ | 1 | x | table1 | +-----------+---------+-----------+ | 2 | x | table2 | +-----------+---------+-----------+ | 3 | x | table3 | +-----------+---------+-----------+ | 4 | x | table4 | +-----------+---------+-----------+ . . .
In my case, "x"=15. In "projdb", i have `userdata`.`userid` as a foreign key referencing `users`.`id` Both userid and id are INT, and `id` is the primary key wi auto increment in `users`. I have set ON UPDATE CASCADE, and ON DELETE CASCADE.Code:ERROR 1062: Duplicate entry '0' for key 'PRIMARY' SQL Statement: INSERT INTO `projdb`.`userdata` (`userid`, `tablename`) VALUES ('15', 'table2') ERROR 1062: Duplicate entry '0' for key 'PRIMARY' SQL Statement: INSERT INTO `projdb`.`userdata` (`userid`, `tablename`) VALUES ('15', 'table3')
Can I bypass this error? Or is my approach wrong?
Any help would be gladly appreciated :<



Reply With Quote



Bookmarks