【正文】
員工編號))1建立工資表create table 工資( 工資編號 char(6) primary key, 員工編號 char(4) not null, 基本工資 money not null, 罰款 money, 獎(jiǎng)金 money, 結(jié)算工資 money, 起始時(shí)間 datetime, 截止時(shí)間 datetime, 發(fā)信日期 datetime, foreign key(員工編號) references 員工(員工編號))第5章 數(shù)據(jù)庫完整性設(shè)計(jì) 主鍵及唯一性索引表名主鍵建立唯一性索引員工(員工編號)create index 員工_學(xué)歷_index on 員工(學(xué)歷)個(gè)人經(jīng)歷(年份,員工編號)create index 個(gè)人經(jīng)歷_任職經(jīng)歷_index on 個(gè)人經(jīng)歷(任職經(jīng)歷)家庭關(guān)系(關(guān)系編號)create index 家庭關(guān)系_親屬關(guān)系_index on 家庭關(guān)系(親屬關(guān)系)管理人員(管理員帳號)create index 管理人員_index on 管理人員(級別)出勤(出勤號)create index 出勤_上班日期_index on 出勤(上班日期)刷卡機(jī)(刷卡機(jī)號)create index 刷卡機(jī)_index on 刷卡機(jī)(刷卡機(jī)號)部門(部門號)create index 部門_領(lǐng)導(dǎo)人員_index on 部門(領(lǐng)導(dǎo)人員)職位調(diào)動(dòng)(調(diào)動(dòng)編號)create index 職務(wù)調(diào)動(dòng)_調(diào)動(dòng)前職務(wù)_index on 職位調(diào)動(dòng)(調(diào)動(dòng)前職務(wù))獎(jiǎng)懲記錄(獎(jiǎng)懲編號)create index 獎(jiǎng)懲記錄_獎(jiǎng)懲類型_index on 獎(jiǎng)懲記錄(獎(jiǎng)懲類型)請假記錄(請假編號)create index 請假記錄_請假天數(shù)_index on 請假記錄(請假天數(shù))工資(工資編號)create index 工資_基本工資_index on 工資(基本工資) 參照完整性設(shè)計(jì) 將個(gè)人經(jīng)歷表中,將“員工編號”設(shè)置為表的外鍵。 Check約束員工表中,將性別進(jìn)行check約束:check(性別 in(39。)) 觸發(fā)器設(shè)計(jì)在職位調(diào)動(dòng)表中,建立更改員工職務(wù)的觸發(fā)器create trigger trigger_職務(wù)修改 on 職位調(diào)動(dòng) for insertasdeclare new_員工編號 char(10),new_調(diào)動(dòng)后職務(wù) char(10)select new_員工編號=員工編號,new_調(diào)動(dòng)后職務(wù)=調(diào)動(dòng)后職務(wù) from insertedupdate 員工 set 職務(wù)=new_調(diào)動(dòng)后職務(wù) where 員工編號=new_員工編號在員工表中,建立插入或刪除員工信息時(shí),修改其相應(yīng)部門的人數(shù)create trigger trigger_增加員工 on 員工 for insertasdeclare new_部門號 char(4),new_員工人數(shù) intselect new_部門號=部門號 from insertedselect new_員工人數(shù)=員工人數(shù) from 部門update 部門 set 員工人數(shù)=new_員工人數(shù)+1 where 部門號=new_部門號create trigger trigger_減少員工 on 員工 for deleteasdeclare new_部門號 char(4),new_員工人數(shù) intselect new_部門號=部門號 from deletedselect new_員工人數(shù)=員工人數(shù) from 部門update 部門 set 員工人數(shù)=new_員工人數(shù)1 where 部門號=new_部門號在職位調(diào)動(dòng)表中,當(dāng)插入信息時(shí),修改調(diào)動(dòng)部門的人數(shù)信息create trigger trigger_部門人數(shù)修改 on 職位調(diào)動(dòng) for insertasdeclare new_前部門號 char(10),new_現(xiàn)部門號 char(10),new_調(diào)動(dòng)后部門號 char(4),new_員工人數(shù) int,new_調(diào)動(dòng)前部門號 char(4)select new_現(xiàn)部門號=調(diào)動(dòng)后部門號,new_前部門號=調(diào)動(dòng)前部門號 from insertedselect new_員工人數(shù)=員工人數(shù) from 部門update 部門 set 員工人數(shù)=new_員工人數(shù)+1 where 部門號=new_現(xiàn)部門號update 部門 set 員工人數(shù)=new_員工人數(shù)1 where 部門號=new_前部門號在獎(jiǎng)懲記錄表中,更新獎(jiǎng)懲信息時(shí),修改工資表中的對應(yīng)的獎(jiǎng)金、罰款create trigger trigger_獎(jiǎng)金 on 獎(jiǎng)懲記錄 for insertasdeclare 獎(jiǎng)金 money,獎(jiǎng)懲類型 char(2),員工編號 char(4)select 獎(jiǎng)金=獎(jiǎng)懲金額,員工編號=員工編號,獎(jiǎng)懲類型=獎(jiǎng)懲類型 from insertedbegin if(獎(jiǎng)懲類型=39。通過這次課程設(shè)計(jì)發(fā)現(xiàn)這其中需要的很多知識我們沒有接觸過,去圖書館查資料的時(shí)候發(fā)現(xiàn)我們前邊所學(xué)到的僅僅是皮毛。我經(jīng)歷了需求分析、概念結(jié)構(gòu)設(shè)計(jì)、邏輯結(jié)構(gòu)設(shè)計(jì)、物理結(jié)構(gòu)設(shè)計(jì)、數(shù)據(jù)庫實(shí)施等過程,對數(shù)據(jù)庫的安全性、完整性層層把握,完善數(shù)據(jù)庫的設(shè)計(jì)。