views:

31

answers:

1

hai guys, i am planning to create a table view and the detail view for the corresponding row, all the datas are fetch from the sqlite database. For this i have created two tables in the database table one for the datas in the table view list and table two for the detail view of the table list. i set the product id as the primary key for the table one. i want the product id as the foreign key for table two. i don't know how to set the foreign key for it and don't know how to retrieve from the table two and display it in the detail view. please help me to do this. Thanks in advance...

A: 

hi,

 1.Change your DB Settings enable to Foreign Keys.

 2.Create the child table like this


   table1 is the parent table having id1 as primary key.

     CREATE TABLE "table1" ("id1" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL)

   table2 is the child table having id2 as a foreign key with reference to  id1 of table1.

CREATE TABLE table2 ( 
      id2           INTEGER, 
      parent_id    INTEGER, 
      description  TEXT,
      FOREIGN KEY (id2) REFERENCES table1(id1)
 )

Use equijoin to retrieve the data from the tables.

 select * from table1,table2 where table1.id1=table2.id2;

 or

 select table2.* from table2,table1 where table1.id1=table2.id2; 

  to retrieve the data from single table alone.

Hope this helps to you!

iphony
thnx iphony....
KingofHeaven