ruby on rails - Scoped AUTO_INCREMENT in MySQL? -
i using mysql in rails application. have users table (standard stuff id, name etc) , books table (again id, user_id , title etc).
i have column (lets call user_book_id) should auto incremented id scoped user_id. id, if record deleted in books table, user_book_id should not reused. example:
user id | name ------------ 1 | jerry 2 | newman book id | user_id | user_book_id | title ----------------------------------- 1 | 1 | 1 | jerry's first book 2 | 1 | 2 | jerry's second book 3 | 2 | 1 | newman's first book 4 | 1 | 3 | jerry's third book
is there way in mysql? searched not find anything.
thanks, prateek
no, no such thing exists. either allow auto_increment unique across table, or have implement yourself.
Comments
Post a Comment