Could anybody tell me how I can change the datatype in SQLite from android?
For example, I want to change varchar(2000)
of a column diary_content
in table diary
to TEXT
. How it is possible?
Could anybody tell me how I can change the datatype in SQLite from android?
For example, I want to change varchar(2000)
of a column diary_content
in table diary
to TEXT
. How it is possible?
Trick that might solve your issue,
You can try something like
To change the datatype of the last_name field to VARCHAR, could do the following:
PRAGMA foreign_keys=off;
BEGIN TRANSACTION;
ALTER TABLE employees RENAME TO _employees_old;
CREATE TABLE employees
( employee_id INTEGER PRIMARY KEY AUTOINCREMENT,
last_name VARCHAR NOT NULL,
first_name VARCHAR,
hire_date DATE
);
INSERT INTO employees (employee_id, last_name, first_name, hire_date)
SELECT employee_id, last_name, first_name, hire_date
FROM _employees_old;
COMMIT;
PRAGMA foreign_keys=on;
Rename existing employees table to _employees_old. Then it will create the new employees table with the last_name field defined as a VARCHAR datatype. Then it will insert all of the data from the _employees_old table into the employees table.
Check SQLite for more details.