0

First time using an Android database for my application. I've researched update statements and I keep seeing examples using a single row ID to update but what if I use a composite key? The only way to find a unique row is with a season number and team name and my database. So I need to create a statement like..

UPDATE table_name
SET wins=5, losses=3
WHERE Team_Name='Something' AND Season='1;

Is this possible? There could be multiple rows(around 8), I would need to do this at a time. And would probably use variables for team name and what not. Thanks for any help.

1
  • for your info you can do almost everything in sqlite database as you do in MySQL except some data type restrictions Commented May 8, 2014 at 14:09

1 Answer 1

2

Yes it is possible. If your season is a string then you would use:

UPDATE table_name 
SET wins = 5, losses = 3 
WHERE Team_Name = 'Something' 
AND Season = '1'

However, if your season is a number then you would use:

UPDATE table_name 
SET wins = 5, losses = 3 
WHERE Team_Name = 'Something' 
AND Season = 1
Sign up to request clarification or add additional context in comments.

3 Comments

So could I just create a String with the update query within a method and at the end db.execSQL(QueryString)
Yes, execSQL(String sql)is for executing a single SQL statement that is NOT a SELECT or any other SQL statement that returns data.
You have SQL Server running on an Android device? What is it with all those tag updates?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.