網頁

2019年11月17日 星期日

[ SQLite ] 資料表之新增更新刪除另創立與欄位重新排列

資料表相關的一些語法與欄位重新排列的語法。

1. 資料表新增欄位語法:
alter table 資料表 add column 欄位名稱 屬性
例如: alter table _t1 add column id integer primary key autoincrement



2. 更改資料表名稱
alter table  資料表1 rename to 資料表2;
例如: alter table  _t1 rename to t1;

3. 資料表中刪除欄位
alter table 資料表 drop column 欄位名稱
例如: alter table t1 drop column id

4. 複製資料表另創新資料表
create table 資料表2 as select name from 資料表1
例如: create table _t1 as select name from t1

5. 刪除資料表
drop table 資料表
例如: drop table t1

6. 重新排列編號後另創資料表的語法
create table 資料表2 as select(select count(*)+1 from 資料表1 as a where a.欄位 < b.欄位 ) as id,name from 資料表1 as b
例如: create table _t2 as select(select count(*)+1 from _t1 as a where a.id < b.id ) as id,name from _t1 as b

7. 重新排列編號後更新的語法
update  資料表 set select(select count(*)+1 from 資料表 as a where a.欄位 < b.欄位 ) as id,name from 資料表 as b
例如: update  _t1 set select(select count(*)+1 from _t1 as a where a.id < b.id ) as id,name from _t1 as b

沒有留言:

張貼留言

影片的問題請留在影片的留言區裡。
部落格不會另外通知給我,所以很難發現你有留言。