sqlite觸發器一例

2021-05-22 13:34:54 字數 1765 閱讀 9069

int column_names_printed = 0;

void print_row(int n_values, char** values)

printf("/n");

}int print_result(void* data, int n_columns, char** column_values, char** column_names)

print_row(n_columns, column_values);

return 0;

}int sqlite()

else printf("open test.db successfully!/n");

rc = sqlite3_exec(db, "begin transaction;", null, null, null);

rc = sqlite3_exec(db, "create table students(number varchar(10), name varchar(10), /

*** varchar(6), age varchar(2));", null, null, null);

rc = sqlite3_exec(db, "insert into students values('00001', 'mary', 'female', '15');/

insert into students values('00002', 'john', 'male', '16');/

insert into students values('00003', 'mike', 'male', '15');/

insert into students values('00004', 'kevin', 'male', '17');/

insert into students values('00005', 'alice', 'female', '14');/

insert into students values('00006', 'susan', 'female', '16');/

insert into students values('00007', 'christina', 'female', '15');/

insert into students values('00008', 'brian', 'male', '16');/

insert into students values('00009', 'dennis', 'male', '14');/

insert into students values('00010', 'daphne', 'female', '18');",

null, null, &errmsg);

rc = sqlite3_exec(db, "commit transaction;", null, null, null);

rc = sqlite3_exec(db, "create  trigger userok_deleteok after delete on students for each row  /

begin /

delete from students where number = '00001' and old.number = '00010' ;/

end;",

null, null, &errmsg);

printf("error code: %d/n", rc);

printf("error message: %s/n", errmsg);

sqlite3_close(db);

return 0;

}

Sqlite 建立觸發器

建立班級表 create table class id integer primary key autoincrement,班級編號 classname nvarchar 50 班級名稱 建立學生表 create table student id integer primary key autoin...

Sqlite 建立觸發器(刪除)

今天在移動裝置上需要做乙個刪除功能,兩個表itembase和itemsd,其中,itembase的id欄位和itemsd的sdpid欄位是一對一關係,現在要求刪除一條itembase的同時也刪除對應的itemsd,於是就想到了使用觸發器,寫法如下 create trigger itembase de...

觸發器詳解 (一)D觸發器

觸發器是時序邏輯電路的基本單元,用來儲存1位2進製資訊,具有記憶和儲存功能,其資訊由雙穩態電路來儲存。觸發器位脈衝邊緣敏感器間,分為上公升沿敏感和下降沿敏感。觸發器的種類很多,由d觸發器,j k觸發器,t觸發器等。並且根據運用場景的不同,觸發器還會有置位,復位,使能和選擇等功能。d觸發器是一種最簡單...