inserted表和deleted表的結構
inserted 表用於儲存 insert 和 update 語句所影響的行的副本。在乙個插入或更新事務處理中,新建行被同時新增到 inserted 表和觸發器表中。inserted 表中的行是觸發器表中新行的副本。
deleted 表用於儲存 delete 和 update 語句所影響的行的複本。在執行 delete 或 update 語句時,行從觸發器表中刪除,並傳輸到 deleted 表中。deleted 表和觸發器表通常沒有相同的行。
173頁第6題
create
database worker_class;
use worker_class;
create
table
work
( work_num char(10
)primary
key,
work_name char(10
),manager char(10
),phone char(11
));create
table calss(
calss_num char(10
)primary
key,
name char(10
),age int
, duty char(10
),salary int(10
),worker_num char(10
),check
(age between
0and60)
,foreign
key(work_num)
references
work
(work_num));
create
unique
index in_name on class(name)
;alter
table workadd constraint fk_name foreign
key(manager)
references calss(name)
;delimiter
// //修改結束符為 //
//當對staff表進行插值時觸發
create
trigger check_age
after
insert
on calss
for each row
begin
declare age int
;set age=new.age;
if age>
60then
delete
from class where age>60;
endif
;end
&//mysql中無法使用check斷言,用觸發器代替
173頁第8題
create
database fraternity;
use fraternity;
create
table m_guest(
m_num char(10
)primary
key,
//男士id
name char(10
));create
table f_guest(
f_num char(10
)primary
key,
//女士id
name char(10
));delimiter
// //修改結束符為//
//當對m_guest表進行插值時觸發
create
trigger check_mnum
after
insert
on m_guest
for each row
begin
declare f_num0 int
;declare m_num0 int
;set f_num0=
(select
count(*
)from f_guest)
;set m_num0=
(select
count(*
)from f_guest);if
(f_num0+m_num0)
>
50then
delete
from m_guest where m_guest.m_num=new.m_num;
endif
;end
&//當對f_guest表進行插值時觸發
create
trigger check_num
after
insert
on f_guest
for each row
begin
declare f_num0 int
;declare m_num0 int
;set f_num0=
(select
count(*
)from f_guest)
;set m_num0=
(select
count(*
)from f_guest);if
(f_num0+m_num0)
>
50then
delete
from f_guest where m_guest.f_num=new.f_num;
endif
;end
&
資料庫作業
設有乙個spj資料庫,包括s,p,j,spj四個關係模式 s sno,sname,status,city p pno,pname,color,weight j jno,jname,city spj sno,pno,jno,qty 商表s由 商 sno 商姓名 sname 商狀態 status 商所在...
資料庫11 9作業
2 實驗內容 2.1 掌握實體完整性約束的建立和使用方法 1 建立表時定義由乙個屬性組成的主鍵 給約束命名 create table s sname char 8 not null,constraint pk sname primary key sname 2 建立表時定義由兩個或兩個以上屬性組成的...
作業14 資料庫
本次作業參考檔案 答 我用的是乙個簡單粗暴的方法 直接重寫儲存資料的那部分方法。分別在library 和userunit類裡面新增connection prestatement resultset屬性,理由jdbcunit類簡化 在main函式開始執行時獲得資料庫連線。books表 users表 借...