0

friends,

I am doing an Android project in my company, still some small work is remaining, I need your help to complete the task.

The problem is...

I have created two tables in which, table1 has an empty column, for purpose for saving name...

The table2 has a list of names, the objective is only the names from this list should be should be saved in the table1's empty column other than that it shouldn't accept any of the name typed manually.

4
  • quite unclear question, plz elaborate..... Commented Sep 2, 2011 at 6:34
  • in table2 column, a list of names had been stored, the objective is the table1 should allow the names from table2 to be stored in it. Commented Sep 2, 2011 at 7:01
  • you mean you want to copy ur table's column's recods into another table ? Commented Sep 2, 2011 at 7:07
  • nope that table2 is created for autocompletetextview... while saving the names in the table2 should stored in table1 condition is table1 should accept the name from table2. Commented Sep 2, 2011 at 7:10

2 Answers 2

1

You appear to want to make the list of names a validation: if the user wishes to save a name to table1, the name must already exist in table2.

Typically this would be done as in the following example, in which only the products listed in PRIZEPRODUCTS can be entered into PRIZEWINNERS table: someone could not win a Boat, for example, given the data below:

 PRIZEPRODUCTS id productname 1|TV 2|iPad 3|backpack PRIZEWINNERS id productid winner ALTER TABLE PRIZEWINNERS ADD CONSTRAINT PRIZEWINNERS_PRIZEPRODUCTS_FK FOREIGN KEY(productid) REFERENCES PRIZEPRODUCTS(id) 

SQLite doesn't create the foreign key using ALTER TABLE but as part of the create-table statement. See here for the syntax. For enabling foreign key support in Android (2.2), see here.

Now, you can establish the foreign key on the [productname] column if [productname] were the key of PRIZEPRODUCTS. In other words, you could make person-name the key of the table rather than having a PersonID. But if that name is changed in the validation table, it can break the foreign key relationship, unless ON UPDATE CASCADE is enabled, but I am not sure if this is supported in Android.

Sign up to request clarification or add additional context in comments.

Comments

0

I hope below query will work for you.

insert into table1(name) values (select name from table2 where id=?).

Thanks.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.