Mint
Mint

Reputation: 47

Multiple tables in one SQLite database

Hey guys I've been looking for a topic about how to create 2 tables in same project ? Would you guys please give me some example or some links for me to look for it :)

private static final String DATABASE_NAME = "CAS_DB";
public static final String tbPerson = "PersonInfo";
public static final String tbColor = "ColorInfo";

what I want is create 2 tables in one database but I can't find any example

Thanks in advance

Upvotes: 2

Views: 9785

Answers (1)

jamapag
jamapag

Reputation: 9318

private static final String PERSON_TABLE_CREATE =
                    "CREATE TABLE " + tbPerson +
                    " (" +
                    PERSON_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    PERSON_NAME + " TEXT);";
private static final String COLOR_TABLE_CREATE =
                    "CREATE TABLE " + tbColor +
                    " (" +
                    COLOR_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    COLOR_NAME + " TEXT);";

And in onCreate method of your database helper:

public void onCreate(SQLiteDatabase db) {
            mDatabase = db;
            mDatabase.execSQL(PERSON_TABLE_CREATE);
            mDatabase.execSQL(COLOR_TABLE_CREATE);
}

Upvotes: 6

Related Questions