SQlite在已建立的表中插入一列 db.execSQL("ALTER TABLE " + table_name + " ADD COLUMN " + column_name + column_type);
SQlite在已建立的表中删除一列 alter table student drop column name // 该行在SQlite中不能用,SQlite不支持drop
qlite中是不支持删除列操做的,因此网上alter table table_name drop column col_name这个语句在sqlite中是无效的,而替代的方法能够以下:1.根据原表建立一张新表 2.删除原表 3.将新表重名为旧表的名称 示例例子以下 1.建立一张旧表Student,包含id(主码),name, tel create table student ( id integer primary key, name text, tel text ) 2.给旧表插入两个值 insert into student(id,name,tel) values(101,"Jack","110") insert into student(id,name,tel) values(102,"Rose","119") 结果如图 3.接下来咱们删除电话这个列,首先根据student表建立一张新表teacher create table teacher as select id,name from student 结果如图 能够看到tel这一列已经没有了 4.而后咱们删除student这个表 drop table if exists student 5.将teacher这个表重命名为student alter table teacher rename to student 结果演示: select * from student order by name desc(desc降序, asc升序) 这样就能够获得咱们想要的结果了。 另外:给本身一个提示,在android sqlite中的查询语句若是是text类型的别忘了给他加上””来指明是String类型的,例如: Cursor c = mSQLiteDatabase.query(TABLE_NAME, null, NAME + "=" + "/"" + name + "/"", null, null,null,null); 方法二: http://www.sqlite.org/faq.html#q11 [java] view plain copy SQLite has limited ALTER TABLE support that you can use to add a column to the end of a table or to change the name of a table. If you want to make more complex changes in the structure of a table, you will have to recreate the table. You can save existing data to a temporary table, drop the old table, create the new table, then copy the data back in from the temporary table. For example, suppose you have a table named "t1" with columns names "a", "b", and "c" and that you want to delete column "c" from this table. The following steps illustrate how this could be done: BEGIN TRANSACTION; CREATE TEMPORARY TABLE t1_backup(a,b); INSERT INTO t1_backup SELECT a,b FROM t1; DROP TABLE t1; CREATE TABLE t1(a,b); INSERT INTO t1 SELECT a,b FROM t1_backup; DROP TABLE t1_backup; COMMIT;