Reputation: 105
Am copying alll values from Table1 to Table2.
Note : In Table2 i have added extra one column at last position.
Table1 has 16 columns
Table2 has 17 columns.
I used the following query :
String s = "INSERT INTO customer_profile_details SELECT * FROM customer_profile";
db.execSQL(s);
It throws the exception as :
03-11 06:34:46.383: E/Copy table(24750): Failed to copy table
android.database.sqlite.SQLiteException: table customer_profile_details has 17 columns but 16 values were supplied (code 1): , while compiling: INSERT INTO customer_profile_details SELECT * FROM customer_profile
How to solve this, i need to pass empty value to new column.
Thanks in advance !
Upvotes: 0
Views: 228
Reputation: 8546
INSERT INTO customer_profile_details (COL1, COL2, COL3, COL4 ... CoL17) SELECT COL1, COL2, COL3, ... Col16 , "constant valid default value for 17 column or null if permitted" FROM customer_profile;
Also it's better to have a default value constraint for the column 17 in table structure itself , to better handle the miss-leading
Upvotes: 0
Reputation: 497
Try this:
String s = "INSERT INTO customer_profile_details SELECT cp.*, null FROM customer_profile cp";
db.execSQL(s);
Upvotes: 2