简体   繁体   中英

Create SQLite Table with name as Record of another Table

I had Created SqLite Table(1) in Android and whenever I enter record/values in that Table I want one more table should be Created whose name must be the values i had Passed/Entered in Table(1).

Please Is there anyone who can help me how to do that??

Inside your class, you can add this method

public void createNewTable(SQLiteDatabase db,String tableName)
    {
        String TABLE_CREATE="CREATE TABLE IF NOT EXISTS "+tableName +
                "(id INTEGER, title TEXT);";
        db.execSQL(TABLE_CREATE);

    }

Here you pass the SQLiteDatabase and the tablename as parameters. Then you create a request string to create your new table with the provided name and customized fields. And then after you execute the query with db.execSQL(TABLE_CREATE) .

you can then call the method inside your insert method(where you insert values in DB). Just after your insertion in the database. Remember to replace fields names by your own names.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM