I tried to copy a table from database1 into database2. with same table
name. But the problem is new table in database2 lost its primary key.
and sqlite seems not able to use Alter table to add new primary key.
need help.

here is how I did it:

mDb.execSQL("DROP TABLE IF EXISTS image");
//here I drop image table in database1



mDb.execSQL("attach  database ? as userdb", new String[]
{mCtx.getDatabasePath("database1").getPath()});
//then I attached database1 to database2,

mDb.execSQL("CREATE TABLE image AS SELECT * FROM userdb.image;");
// copy image table from database1 (now as named userdb) into
database2.

At this point. I successfully copy image table. but new image table in
database2 lost its primary.   "_id" column was primary key in
database1 before, now it became just normal integer in database2.

I also tried  mDb.execSQL("ALTER TABLE image ADD PRIMARY KEY (_id);"),
but with no luck. I check SQLite office site. it doesn't support ALTER
TABLE to add primary key.

please someone give me a hint how to solve this problem.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to