乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

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

       豆芽愛(ài)尚閱 2015-12-12

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

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

      2.刪除原表

      3.將新表重名為舊表的名稱(chēng)

      示例例子如下

      1.創(chuàng)建一張舊表Student,包含id(主碼),name, tel

      create table student (

      id integer primary key,

      name text,

      tel text

      )

      2.給舊表插入兩個(gè)值

      insert into student(id,name,tel) values(101,"Jack","110")

      insert into student(id,name,tel) values(102,"Rose","119")

      結(jié)果如圖

      clip_image002

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

      create table teacher as select id,name from student

      結(jié)果如圖

      clip_image004

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

      4.然后我們刪除student這個(gè)表

      drop table if exists student

      5.將teacher這個(gè)表重命名為student

      alter table teacher rename to student

      結(jié)果演示:

      select * from student order by name desc(desc降序, asc升序)

      clip_image006

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

      另外:給自己一個(gè)提示,在android sqlite中的查詢(xún)語(yǔ)句如果是text類(lèi)型的別忘了給他加上””來(lái)指明是String類(lèi)型的,例如:

      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;  

       

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

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶(hù) 評(píng)論公約

        類(lèi)似文章 更多