![](/img/trans.png)
[英]How to get the name of the last column from the SQL table without traversing in SQLite3?
[英]How to delete the multiple columns from the SQL table in SQlite3?
我的數據庫包含“n”個列:
name Phone_no Person_1 Person_2 Person_3 Person_4
john 123 1 2 3 4
Nolan 1234 23 34 1 5
如果 Phone_no 是 1234,那么我想刪除 Person_1、Person_3 列。
我知道必須刪除的列號(第 3 列(Person_1)、第 5 列(Person_3))。
這是你想要的嗎?
update mytable set person_1 = null, person_5 = null
where phone_no = 1234
我知道通過刪除phone_no
為 1234 的person_1
和person_3
列,您的意思是將person_1
和person_3
列中的值設置為 null ,其中phone_no
為 1234 。
如果您想實際刪除列,那么這是一個不同的問題。 在 SQLite 中,您需要重新創建表:
create table tmp_table(
name varchar(50), -- adapt the datatypes and lengths to your requirement
phone_no int,
person_2 varchar(50),
person_4 varchar(50)
);
insert into tmp select name, phone, person_2, person_4 from mytable;
drop table mytable;
create table mytable(
name varchar(50),
phone_no int,
person_2 varchar(50),
person_4 varchar(50)
);
insert into mytable select name, phone, person_2, person_4 from tmp_table;
drop table tmp_table;
有沒有辦法通過單個 SQL 語句刪除多個列。
另一種方法是多次運行單個 SQLite3 語句: https ://stackoverflow.com/a/16162224/3426192
例如:SQLite 2021-03-12 (3.35.0) 現在支持: DROP COLUMN
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.