Creates table by building create table sql statement and execute it - Android Database

Android examples for Database:Table Create

Description

Creates table by building create table sql statement and execute it

Demo Code


//package com.java2s;

import android.database.sqlite.SQLiteDatabase;

import android.util.Log;

public class Main {
    private static final String LOG_TAG = "BoardDatabaseOpenHelper";

    private static void createGameEngineStateTable(SQLiteDatabase db) {
        Log.d(LOG_TAG, "Creating game engine state table");
        StringBuilder sql = new StringBuilder();

        sql.append("CREATE TABLE GameEngineState (");
        sql.append("Engine smallint,");
        sql.append("Id smallinit,");
        sql.append("Row smallint,");
        sql.append("Column smallint,");
        sql.append("Chip smallint,");
        sql.append("State smallint,");
        sql.append("PRIMARY KEY (Engine, Id, Row, Column),");
        sql.append("FOREIGN KEY (Engine) REFERENCES GameEngine(Id)");
        sql.append(");");

        db.execSQL(sql.toString());//ww  w . j a  v  a 2s. c  om
    }
}

Related Tutorials