Rename Column if Exists sqlite? -
i've created used column not being used setting , getting values
i found column name not correct , want change column name want retain data of existing database in device
is there query check , rename sqlite column
alter table mytable rename column if exists mycolumn mycolumn1;
existing database @ user end used user's throw out india please me
note:
1. don't want threw exception
2. not want recreate table
i know both way accomplish task that's not best practice
rather recreating i'll live poor name
i think there solution can check table hope check column
select name sqlite_master type='table' order name;
or
select name sqlite_master type='table' , name = 'mytable';
as far know there no way ask. can use
select sql sqlite_master tbl_name = 'table_name' , type = 'table'
to check whether column exists or not. since have rename column once not know issue recreation of table. recreation not mean data loss.
the procedure along lines of:
begin transaction;
alter table table rename tmp_table;
create table table (columnnames);
insert table(columnnames) select columnnameswrong tmp_table;
drop table tmp_table_name;
commit;
if fuss use tool it.
about best practice part, best practice tables named properly. since build queries around field names renaming columns means breaking queries. not know looking sqlite manual states:
sqlite supports limited subset of alter table. alter table command in sqlite allows user rename table or add new column existing table. not possible rename column, remove column, or add or remove constraints table.
note not possible.
Comments
Post a Comment