2

I would like to know how to insert a default value to a table when it's created using Android Sqlite.

2
  • which data type you want to insert? Commented May 26, 2014 at 7:00
  • TEXT datatype. I need it when creating the table Commented May 26, 2014 at 7:02

1 Answer 1

2

try this,it uses both text and integer type
replace MyTableName with yourtable

 @Override
            public void onCreate(SQLiteDatabase paramSQLiteDatabase) { // sqlite oncreate method
        paramSQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS MyTableName(_id INTEGER DEFAULT 0,name TEXT DEFAULT 'ram');");
        }
Sign up to request clarification or add additional context in comments.

2 Comments

Which error you got?I tested this command on Sqlite browser and its working
it's not working because probably you've already created this database, try uninstall app/clear app and try again

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.