i've been developing android app with my friend for my school project, and he did the database part, we using SQLite, and i wanna use the database scheme that he created, but the table are already defined, how can i somehow, rename the table and insert my own data in it without changing the scheme? we both use the same project folders so it kinda makes me stuck right now, thanks.
Asked
Active
Viewed 474 times
1
-
Post the dbhelper code here, i have an idea but without code i can't help better – Bruno Ferreira Aug 02 '17 at 14:54
-
`rename the table and insert my own data in it without changing the scheme?` That makes no sense, to me. If you alter table name, the db schema is altered. – Phantômaxx Aug 02 '17 at 14:54
-
Anyway, you can use ALTER TABLE. – Phantômaxx Aug 02 '17 at 14:54
-
@ModularSynth I'm assuming he means that the columns will remain the same, just the name of the table to be changed. – Michael Dodd Aug 02 '17 at 14:57
-
@MichaelDodd And.,. my comment remains valid. – Phantômaxx Aug 02 '17 at 14:58
-
1@ModularSynth I'm not doubting your comment, just stating my interpretation of the question even if the question itself doesn't entirely make sense. – Michael Dodd Aug 02 '17 at 15:00
-
imagine like i got table A, inside table A, there is B, C, D, E column. i want to rename the table name into table F, but the column remain B C D E, and i want to use my own data on table F, not the data defined and inserted in table A, any suggestion? – wh gaming Aug 02 '17 at 15:20
-
@whgaming So you want to keep table A, and copy its structure as table F? Or create table F and get rid of table A? – Michael Dodd Aug 02 '17 at 15:43
-
either way is fine. but i prefer to get rid of table A since its my friend's – wh gaming Aug 02 '17 at 15:59
-
@whgaming Those two scenarios have two very different answers. If you don't need table A, try my answer below. If you do need to keep table A, you'll likely need [this answer by CL.](https://stackoverflow.com/a/12753695/469080). – Michael Dodd Aug 02 '17 at 16:01
-
1i'll try it, thank you for the answer, i apreciate it, i'm a new java/android programmer, please guide me in the future as well :) – wh gaming Aug 02 '17 at 16:05
1 Answers
2
By using Alter Table:
ALTER TABLE oldTableName RENAME TO newTableName
Obviously replacing oldTableName
and newTableName
with whatever you choose. Then you can INSERT INTO
your table using the new name. Keep in mind that any references to this old table will also need to be updated.
Also take care if you're using any triggers:
Important Note: The
'ALTER TABLE ... RENAME TO ...'
command does not update action statements within triggers or SELECT statements within views. If the table being renamed is referenced from within triggers or views, then those triggers and views must be dropped and recreated separately by the application.

Michael Dodd
- 10,102
- 12
- 51
- 64