[sqlite] Change a field type

2013-03-23 Thread Marco Turco
Hi,

I have a table with one field defined as smallint(3) and I would like to
change the field type now in char(3) (without lost the value inside).

How can I make the change ? Do I need to create a new table with the new
fields where import the current data or is there a better method ?

 

Thanks in advance

 

Marco

 

 

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] Change a field type

2013-03-23 Thread Simon Slavin

On 23 Mar 2013, at 4:07pm, Marco Turco m.tu...@softwarexp.co.uk wrote:

 I have a table with one field defined as smallint(3) and I would like to
 change the field type now in char(3) (without lost the value inside).
 
 How can I make the change ? Do I need to create a new table with the new
 fields where import the current data or is there a better method ?

First, SQLite doesn't have smallint or char types.  It will understand those as 
INTEGER and TEXT affinities.

Second, one way do to what you want is to use the SQLite shell tool:

http://www.sqlite.org/sqlite.html

You can download a precompiled version from the SQLite download page.  Use the 
'.dump' command to write your whole database (or maybe just the table) as SQL 
commands.  Then use a text editor to change the command that creates that 
table.  Then use the '.read' command to read that file in, which will make the 
new table and put the data back in again.

Simon.
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users