日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

SQlite在已創(chuàng)建的表中刪除一列--解決方案

 豆芽愛尚閱 2015-12-12

sqlite中是不支持刪除列操作的,所以網(wǎng)上alter table table_name drop column col_name這個語句在sqlite中是無效的,而替代的方法可以如下:

1.根據(jù)原表創(chuàng)建一張新表

2.刪除原表

3.將新表重名為舊表的名稱

示例例子如下

1.創(chuàng)建一張舊表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")

結果如圖

clip_image002

3.接下來我們刪除電話這個列,首先根據(jù)student表創(chuàng)建一張新表teacher

create table teacher as select id,name from student

結果如圖

clip_image004

可以看到tel這一列已經(jīng)沒有了

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升序)

clip_image006

這樣就可以得到我們想要的結果了。

另外:給自己一個提示,在android sqlite中的查詢語句如果是text類型的別忘了給他加上””來指明是String類型的,例如:

Cursor c = mSQLiteDatabase.query(TABLE_NAME, null, NAME + "=" + "/"" + name + "/"", null, null,null, null);

 

方法二:

http://www./faq.html#q11

  1. 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.  
  2.   
  3. 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:   
  4.   
  5. BEGIN TRANSACTION;  
  6. CREATE TEMPORARY TABLE t1_backup(a,b);  
  7. INSERT INTO t1_backup SELECT a,b FROM t1;  
  8. DROP TABLE t1;  
  9. CREATE TABLE t1(a,b);  
  10. INSERT INTO t1 SELECT a,b FROM t1_backup;  
  11. DROP TABLE t1_backup;  
  12. COMMIT;  

 

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多