alter sqlite table to add unique constraint on multiple columns
<p>I have a ContentProvider backed by an sqlite table. So to create my table I used</p>

<pre><code>public class H extends SQLiteOpenHelper {
  @Override
  public void onCreate(SQLiteDatabase sqliteDatabase) {
    …// here I defined my original table without constraints
  }
}
</code></pre>

<p>When originally created, the table had the columns: name, age, height. No Constraints. Nothing.</p>

<p>Now I need to add constraints to the table. So I increased the DATABASE_VERSION, and then in the onCreate String I added <code>UNIQUE(name,age) ON CONFLICT REPLACE</code>.
My question is, what should I do inside the <code>onUpgrade</code> method? Stated more simply: How do I call <code>ALTER TABLE</code> just for adding constraints? My attempt failed</p>

<pre><code>ALTER TABLE myTable ADD UNIQUE(name,age) ON CONFLICT REPLACE
</code></pre>

<p>Here is the error message:</p>

<pre><code>Caused by: android.database.sqlite.SQLiteException: near "CONSTRAINT": syntax error (code 1): , while compiling: ALTER TABLE myTable ADD CONSTRAINT UNIQUE(name,age) ON CONFLICT REPLACE
#################################################################
Error Code : 1 (SQLITE_ERROR)
Caused By : SQL(query) error or missing database.
    (near "CONSTRAINT": syntax error (code 1): , while compiling: ALTER TABLE myTable ADD CONSTRAINT UNIQUE(name,age) ON CONFLICT REPLACE)
</code></pre>