【正文】
t,sc where = and sdept=@p group by o ) select * from (39。cs39。)drop function aver求某個院系選修了某門課的學(xué)生人數(shù)。create function people(@p0 char(10),@p1 char(4)) returns intas begin declare @renshu int select @renshu = ( select COUNT(*) 選課人數(shù) from student,sc where = and o = @p1 and sdept = @p0 ) return @renshu end select (39。cs39。,39。239。)drop function people。 Create trigger XXX On table [ for /after /instead of ] Insert,delete,update As 觸發(fā)器實(shí)際需要觸發(fā)內(nèi)容For:用法同afterAfter:執(zhí)行完sql語句之后進(jìn)行檢查,檢查不符合條件的話回滾 roll back 。after觸發(fā)器只能在表上指定。Instead of :指定觸發(fā)器時代替SQL語句執(zhí)行的,其優(yōu)先級高于觸發(fā)語句的操作。例:為 student表建立觸發(fā)器T1,當(dāng)插入或更新表中的數(shù)據(jù)時,保證所操作的記錄的sage值大于0。create trigger T1on studentafter insert,updateas begin declare @sage int select @sage = from inserted if(@sage 0) begin print 39。年齡錯誤39。 rollback transaction endendupdate studentset sage = 38where sno = 39。0139。insert into student(sno,sname,ssex,sage,sdept)values(39。200701139。,39。張三39。,39。男39。,55,39。ma39。)為student表建立觸發(fā)器T2,禁止刪除編號為“0001”的學(xué)生。insert into student(sno,sname,ssex,sage,sdept)values(39。000139。,39。傻大個39。,39。男39。,19,39。is39。)create trigger T2on studentafter deleteasbegin declare @sno char(10) select @sno = from deleted if(@sno = 39。000139。) begin print 39。禁止刪除學(xué)號0001信息39。 rollback transaction endenddelete student where sno = 39。000139。drop trigger T2第十章1.事務(wù)。 是一系列的數(shù)據(jù)庫操作,是數(shù)據(jù)庫應(yīng)用程序的基本邏輯單元。 是用戶定義的一個數(shù)據(jù)庫操作序列,這些操作要么全做,要么全不做,是一個不可分割的工作單元。2.事務(wù)的四個特性。 原子性:事務(wù)是數(shù)據(jù)庫的邏輯工作單位,事務(wù)總包括的諸操作要么全做,要么全不做。 一致性:數(shù)據(jù)庫只包含成功事務(wù)提交的結(jié)果,就說數(shù)據(jù)庫處于一致性狀態(tài)。 隔離性:一個事務(wù)的執(zhí)行不能被其他事務(wù)干擾。即一個事務(wù)的內(nèi)部操作及使用的數(shù)據(jù)對其他并發(fā)事務(wù)是隔離的,并發(fā)執(zhí)行的各個事務(wù)之間不能互相干擾。 持續(xù)性:指一個事務(wù)一旦提交,他對數(shù)據(jù)庫中數(shù)據(jù)的改變就應(yīng)該是永久性的。事務(wù)是恢復(fù)和并發(fā)控制的基本單位。3.?dāng)?shù)據(jù)庫恢復(fù)。 把數(shù)據(jù)庫從錯誤狀態(tài)恢復(fù)到某一已知的正確狀態(tài)的功能。1. 運(yùn)行事務(wù)非正常中斷。2. 數(shù)據(jù)丟失。4.故障種類。 運(yùn)行事務(wù)非正常中斷恢復(fù)事務(wù)撤銷。 系統(tǒng)故障、介質(zhì)故障、計算機(jī)病毒。5.恢復(fù)實(shí)現(xiàn)技術(shù)。數(shù)據(jù)恢復(fù)的基本原理:冗余。 建立冗余數(shù)據(jù)最常用的技術(shù)是數(shù)據(jù)轉(zhuǎn)儲和登記日志文件。6. 數(shù)據(jù)轉(zhuǎn)儲。 靜態(tài)轉(zhuǎn)儲:是在系統(tǒng)中無運(yùn)行事務(wù)時進(jìn)行的轉(zhuǎn)儲操作。 動態(tài)轉(zhuǎn)儲:是指轉(zhuǎn)儲期間允許對數(shù)據(jù)庫進(jìn)行存取或修改。即轉(zhuǎn)儲和用戶事務(wù)可以并發(fā)執(zhí)行。 海