sqlite學習筆記4:表的建立和刪除,sqlite學習筆記

來源:互聯網
上載者:User

sqlite學習筆記4:表的建立和刪除,sqlite學習筆記

前面做了那麼多不就是為了資料弄幾張表麼,接下來看看怎麼建立表。

一 建立表

基本文法如下:

CREATE TABLE database_name.table_name(   column1 datatype  PRIMARY KEY(one or more columns),   column2 datatype,   column3 datatype,   .....   columnN datatype,);

其中database_name為你的資料庫名,table_name當然是表名啦,columnN為列明,PRIMARY_KEY是主鍵,datatype為本列的資料類型。

例如,建立一張使用者表:

CREATE TABLE USER(   ID INT PRIMARY KEY     NOT NULL,   NAME           TEXT    NOT NULL,   AGE            INT     NOT NULL,   ADDRESS        CHAR(50));

# “NOT NULL”指定當前列不可為空

建立完之後可以通過如下命令查看建立的表:

.tables
要查看錶的詳細結構,使用命令:

.schema

二 刪除表

使用命令:

DROP TABLE database_name.table_name;






怎在sqlite3中刪除表欄位,我不想在可視化介面中刪除,想直接用命令刪除下面是我寫的,但是語法錯誤

sqlite不支援刪除列。可以這樣:
1. 根據Publisher表,建立一個publisher_temp表(不含欄位state_province)

2. 複製資料到publisher_temp中
3. 刪除Publisher表

4. 把publisher_temp表改名
 
sqlite3怎刪除指定行資料?(如要刪除資料表中第五行資料),賜教

刪除tmp表第五行資料
delete from tmp where rowid in(select rowid from tmp limit 1 offset 4);
 

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.