1. 程式人生 > >【資料庫】sqlite3常用命令

【資料庫】sqlite3常用命令

.table

檢視資料庫所有的表格名稱

.h on

可查看錶中的欄位名

.q

正常退出資料庫

select * from user

獲取user資料表中所有的資料

update user set value='1' where id='0';

將user資料表中 id等於0,欄位名為value的值設定為1

 

.schema

在沒有引數的情況,它會顯示最初用於建立資料庫的CREATE TABLE和CREATE INDEX的SQL語句

建立資料表,建立一個snmp表,成員如下

struct snmp
{
	int v1_enable;
	int v2c_enable;
	char write_community[MAX_LEN_64];
	char read_community[MAX_LEN_64];

	int v3_enable;
	char read_security_name[MAX_LEN_64];
	int read_level_security;//0=auth,priv 1=auth,no priv 2=no auth,no priv
	int read_auth_algorithm;//0=MD5 1=SHA
	char read_auth_password[MAX_LEN_64];
	int read_pri_algorithm;//0=DES 1=AES
	char read_pri_password[MAX_LEN_64];

	char write_security_name[MAX_LEN_64];
	int write_level_security;//0=auth,priv 1=auth,no priv 2=no auth,no priv
	int write_auth_algorithm;//0=MD5 1=SHA
	char write_auth_password[MAX_LEN_64];
	int write_pri_algorithm;//0=DES 1=AES
	char write_pri_password[MAX_LEN_64];

	int port;
};
CREATE TABLE snmp ("v1_enable" INTEGER, "v2c_enable" INTEGER, "read_community" TEXT NOT NULL, "write_community" TEXT NOT NULL, "v3_enable" INTEGER, "read_name" TEXT NOT NULL, "read_level" INTEGER, "read_auth_type" INTEGER, "read_auth_psw" TEXT NOT NULL, "read_pri_type" INTEGER, "read_pri_psw" TEXT NOT NULL, "write_name" TEXT NOT NULL, "write_level" INTEGER, "write_auth_type" INTEGER, "write_auth_psw" TEXT NOT NULL, "write_pri_type" INTEGER, "write_pri_psw" TEXT NOT NULL, "port" INTEGER);

insert into snmp values('0', '0', 'public', 'private', '0', '', '2', '0', '', '0', '', '', '2', '0', '', '0', '', '161');

插入新的資料也可以這樣寫:先把欄位名寫前面,之後用values把所有的資料補充上

insert into vca_people_event(id,enable,tri_alarms,tri_channels_ex) values(0,0,0,'1000000000000000000000000000000000000000000000000000000000000000');

 

在原有的資料表中插入新的欄位:在network中新增若干欄位

alter table network add column "lan1_ip6_address" TEXT default "";
alter table network add column "lan1_ip6_netmask" TEXT default "";
alter table network add column "lan1_ip6_gateway" TEXT default "";
alter table network add column "lan2_ip6_address" TEXT default "";
alter table network add column "lan2_ip6_netmask" TEXT default "";
alter table network add column "lan2_ip6_gateway" TEXT default "";
alter table network add column "lan1_ip6_dhcp" INTEGER;
alter table network add column "lan2_ip6_dhcp" INTEGER;
alter table network add column "bond0_ip6_dhcp" INTEGER;
alter table network add column "bond0_ip6_address" TEXT default "";
alter table network add column "bond0_ip6_netmask" TEXT default "";
alter table network add column "bond0_ip6_gateway" TEXT default "";