Yes Simon. I am looking for it. ON DELETE RESTRICT. I got the answer.
Should I enable foreign key support to use on delete restrict?( http://www.sqlite.org/foreignkeys.html) I have x databases without enabling foreign key support. Can I enable foreign key support for x+1 database only? On Wed, Jun 12, 2013 at 2:01 PM, Simon Slavin <slav...@bigfraud.org> wrote: > > On 12 Jun 2013, at 9:49am, dd <durga.d...@gmail.com> wrote: > > >>> Book titles are not unique. > > I agree. 2. Books : columns(BookId_primarykey, > > Book_id_in_string_format_like_guid) > > I’m not sure why you would need a GUID. You can store > > 2. Books : columns(BookId_primarykey, Title) > > Just don’t put a restriction on it that the title must be unique. The > BookId is unique and that is enough. > > > > >>> Why is there a problem when there is an author without any books? > > No problem. But, my app need to delete author record from author > > table when author doesn't have any books. How to handle this? (I can > verify > > in author table, whether this author belongs to any other book when book > > deletion. If no, delete from author table. I am not happy with this > > solution ) > > The normal way to do this in a SQLite database would be to use a FOREIGN > KEY relationship: > > <http://www.sqlite.org/foreignkeys.html> > > You would have something like this: > > 1. Authors: columns(AuthorId, Name, SSN) > 2. Books : columns(BookId, Title, AuthorId, > FOREIGN KEY(AuthorId) REFERENCES Authors(AuthorId)) > > You could set the database up in two ways: > > (A) ON DELETE CASCADE would allow you to delete an author with books, and > would delete their books too. > (B) ON DELETE RESTRICT would make SQLite issue an error message if you > tried to delete an author who still had books in the Books table. > > SQLite will do this itself automatically. You do not need to write your > own code to look at the other table. > > Simon. > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users