【正文】
after insert as begin declare @new_num intdeclare @new_num1 intdeclare @new_date varcharselect @new_num=(select 加班 from inserted)select @new_num1=(select 請(qǐng)假 from inserted)select @new_date=(select 日期 from inserted)update 工資 set 加班工資=@new_num*100,缺勤扣款=@new_num1*100 where 員工編號(hào) in (select 員工編號(hào) from inserted) End。(2) 當(dāng)考勤表添加一條記錄,考勤表中的出勤天數(shù)自動(dòng)添加Create trigger insert_考勤 2On 考勤 For insertAs begin 17update 考勤 set 出勤天數(shù)=20休假請(qǐng)假 where 員工編號(hào) in (select 員工編號(hào) from inserted) end。(3)當(dāng)工資表中添加一條新的記錄, “應(yīng)發(fā)工資”和“實(shí)發(fā)工資 ”自動(dòng)填充create trigger insert_1on 工資 for insert,updateas beginupdate 工資 set 應(yīng)發(fā)工資=基本工資+崗位工資+工齡工資+加班工資+其他應(yīng)增款缺勤扣款其他應(yīng)減款,實(shí)發(fā)工資=基本工資+ 崗位工資+ 工齡工資+加班工資+其他應(yīng)增款缺勤扣款其他應(yīng)減款個(gè)人所得稅 where 員工編號(hào) in (select 員工編號(hào) from inserted)End。(4) 當(dāng)工資表中添加一條新的記錄,表“工資歷史”的內(nèi)容自動(dòng)填充create trigger insert_2on 工資 after insertas begin declare @bb varchar(10)declare @cc decimal(12,4)declare @dd varchar(15)select @bb=員工編號(hào) from insertedselect @cc=實(shí)發(fā)工資 from 工資 select @dd=工資年月 from insertedInsert into 工資歷史 values( @bb, @cc, @dd)End。(5)當(dāng)考勤表的觸發(fā)器觸發(fā)工資表進(jìn)行 update 時(shí),工資表中的實(shí)發(fā)工資改變,使 “工資歷史” 表的發(fā)放金額自動(dòng)改變create trigger insert_3on 工資 after update as begin declare @new_aa decimaldeclare @date varchar(15)set @new_aa=(select 實(shí)發(fā)工資 from inserted)set @date=(select 工資年月 from inserted)update 工資歷史 set 發(fā)放金額= @new_aa where 員工編號(hào) in (select 員工編號(hào) from inserted) end。(6)當(dāng)員工表刪除或增加一個(gè)員工時(shí),對(duì)應(yīng)的部門(mén)人數(shù)相應(yīng)變化Create trigger delete_員工on 員工 after delete18as beginupdate 部門(mén) set 部門(mén)人數(shù)=部門(mén)人數(shù)1 where 部門(mén)名稱(chēng) in (select 部門(mén)名稱(chēng) from deleted)end。create trigger insert_員工on 員工 after insertas beginupdate 部門(mén) set 部門(mén)人數(shù) =部門(mén)人數(shù)+1 where 部門(mén)名稱(chēng) in (select 部門(mén)名稱(chēng) from inserted)end。 建立索引為提高檢索性能,為表創(chuàng)建符合索引,其索引項(xiàng)為員工編號(hào)、姓名。Create index 員工編號(hào)_姓名_indOn 員工(員工編號(hào),姓名)。7. 1 簡(jiǎn)單查詢(1)員工基本信息情況,代碼如下:(2)員工考勤情況,代碼如下19(3)員工的基本工資設(shè)定,代碼如下(4)按照基本工資和考勤,產(chǎn)生的工資,代碼如下select * from 工資。 復(fù)雜查詢(1)企業(yè)內(nèi)部財(cái)務(wù)部的工資查詢,代碼如下:select , ,實(shí)發(fā)工資 from 員工,工資 where = and 部門(mén)名稱(chēng)=39。財(cái)務(wù)部39。20(2)企業(yè)工資報(bào)表,能查詢單個(gè)員工的工資select ,姓名,工資年月,基本工資,崗位工資,工齡工資,加班工資,缺勤扣款,其他應(yīng)減款,其他應(yīng)增款,應(yīng)發(fā)工資,實(shí)發(fā)工資from 工資,員工 where = and 姓名 like 39。張%39。(3)每個(gè)部門(mén)的工資情況,按月統(tǒng)計(jì)select 部門(mén)名稱(chēng),avg(實(shí)發(fā)工資 ) from 工資,員工 where = group by 部門(mén)名稱(chēng)。 數(shù)據(jù)庫(kù)的用戶與權(quán)限管理(1)數(shù)據(jù)庫(kù)的用戶管理GZGL 庫(kù)的用戶21dbo 用戶屬性數(shù)據(jù)庫(kù)登陸文件夾22Sa 登陸屬性建立新用戶:用戶名 U1,密碼 1234(登陸名 login1)Create login login1 with password=’1234’。Use GZGL。Create user U1 for login1。(2)用戶權(quán)限管理系統(tǒng)權(quán)限管理對(duì)象權(quán)限管理,設(shè)置權(quán)限將員工表的錄入、查詢授予給 U1 用戶GRANT SELECT,INSERT ON TABLE 員工 TO U1。 數(shù)據(jù)庫(kù)的備份對(duì) GZGL 庫(kù)進(jìn)行備份單擊備份右鍵進(jìn)行備份23 數(shù)據(jù)的導(dǎo)出與導(dǎo)入1)數(shù)據(jù)的導(dǎo)出248 總結(jié)經(jīng)過(guò)這段時(shí)間的努力,我們組在老師的幫助下,基本完成本次的課程設(shè)計(jì),基本達(dá)到了工資管理系統(tǒng)的要求。經(jīng)過(guò)這次數(shù)據(jù)庫(kù)課程設(shè)計(jì)給我們留下了很大的印象,明白了流程是一切的根本,架構(gòu)是骨骼。實(shí)踐比一切的空談和理論更能學(xué)到東西。在做這個(gè)數(shù)據(jù)庫(kù)開(kāi)始無(wú)論遇到什么困難,我們都沒(méi)有一絲的放棄念頭。也體會(huì)到,在設(shè)計(jì)過(guò)程中一定要慎重,仔細(xì),來(lái)不得半點(diǎn)馬虎。需求分析是整個(gè)課程設(shè)計(jì)的中心,考慮全面,分析徹底。才會(huì)為后來(lái)的設(shè)計(jì)打下良好的基礎(chǔ)。否則,前功盡棄,甚至不能完成任務(wù)。做實(shí)例過(guò)程中要注意一說(shuō)明書(shū)中數(shù)據(jù)項(xiàng)類(lèi)型,數(shù)據(jù)長(zhǎng)度等一致,不能像平時(shí)在紙上作業(yè)。最后,通過(guò)這次課程設(shè)計(jì)讓我們學(xué)到了很多,強(qiáng)化了動(dòng)手能力,加強(qiáng)了合作意識(shí),為以后找工作奠定了一定的基礎(chǔ)。