- •Отчет о курсовой работе по курсу «Базы данных»
- •Содержание работы
- •1 Инфологическое проектирование
- •1.1 Анализ Предметной области
- •1.2 Анализ информационных задач и круга пользователей системы
- •2 Определение требований к операционной обстановке
- •3 Выбор субд и других программных средств
- •4 Логическое проектирование бд
- •4. 3 Составление реляционных отношений
- •4.4 Нормализация полученных отношений(до 4нф)
- •4. 6 Определение дополнительных ограничений целостности
- •4.7 Описание групп пользователей и прав доступа
- •5 Реализация проекта базы данных
- •5.1 Создание таблиц
- •5.2 Создание представлений, готовых запросов
- •5.3 Назначение прав доступа
- •5.4 Создание индексов
- •5.5 Разработка стратегии резервного копирования
- •6 Список литературы
5.2 Создание представлений, готовых запросов
1 Список действующих полисов:
Create view curr_policy as
Select *
From Policy
Where (EffectiveDate<=curdate()) and (ExpirationDate>=curdate());
2 Список оформленных полисов за последние 30 дней:
Create view Days_policy as
Select *
From Policy
Where (DateAcceptation <=curdate()) and (DateAcceptation >=curdate()-30);
3 Просмотр всех страховых взносов, внесенных по полисам за последние 30 дней:
Create view Days_Fee as
Select p.Fee, i.Surname, i.FirstName, i.Patronimic, pol. DateAcceptation
From put_money p, Policy pol
Where ((pol.DateAcceptation <=curdate()) and (pol.DateAcceptation >=curdate()-30)) and (p.NumberSer=pol.NumberSer) ;
4 Просмотр всех страховых выплат, рассчитанных за последние 30 дней:
Create view Days_Pay as
Select p. PaymentDeath, p. PaymentSurv, i.Surname, .FirstName, i.Patronimic, pol. DateAcceptation
From Payment p, Insured i, Policy pol
Where ((pol.DateAcceptation <=curdate()) and (pol.DateAcceptation >=curdate()-30)) and (p.NumberSer=pol.NumberSer) and (pol.PassD=i.Pass);
5 Список действующих полисов, по которым уже произведены выплаты:
Create view Pays_policy as
Select *
From Policy
Where Stat= 'payments used' and (EffectiveDate<=curdate()) and (ExpirationDate>=curdate());
6 Сколько полисов оформили сотрудники за 30 дней:
Create view Num_Policy (Name, department, NumPol) as
Select w.Surname + ‘ ‘ + w.FirstName + ‘ ‘ + w.Patronimic, dep.Work_dep,
count(case when p.NumberSer=dep.SerNum then 1 else null end) Pol
From Work_policy dep, worker_SK w, Policy p
Where (w.id =dep.id)
Group by dep.Work_dep;
7 Просмотр своего полиса (Страхователь, Застрахованный, Выгодоприобретатель)
Create view My_Policy as
Select p.*
From Policy p, Insurer r, Insured d, Beneficiary b
Where ((r.Pass=user) and (p.PassR=r.Pass)) or( (d.Pass=user) and (p.PassD=d.Pass)) ) or ((b.Pass=user) and (b. NumberSer=p. NumberSer) );
8 Список полисов, по которым уплачены взносы № (действующих):
Create view Sum_FeeYes as
Select p.NumberSer, p.SumPolicy, Sum(put.Fee)
From Policy p, put_money put
Where ((p.NumberSer=put.NumberSer) and (Sum(put.Fee)=p.SumPolicy)) and ((EffectiveDate<=curdate()) and (ExpirationDate>=curdate()));
9 Список полисов, по которым НЕ уплачены взносы № (действующих):
Create view Sum_FeeNo as
Select p.NumberSer, p.SumPolicy, Sum(put.Fee)
From Policy p, put_money put
Where ((p.NumberSer=put.NumberSer) and (Sum(put.Fee)<p.SumPolicy)) and ((EffectiveDate<=curdate()) and (ExpirationDate>=curdate()));
5.3 Назначение прав доступа
Опишем для каждой группы пользователей права доступа к представлениям. Права приведены в таблице ниже. Используются следующие сокращения:
s – чтение данных (select);
i – добавление данных (insert);
u – модификация данных (update);
d – удаление данных(delete).
Таблицы |
Группы пользователей (роли) | |||||
Должностные лица СК |
Начальство СК |
Страхователь |
Застрахованный, Выгодоприобретатель |
Бухгалтерия СК |
Администратор БД | |
Curr_Policy |
SIUD |
S |
- |
- |
S |
S |
Days_Policy |
S |
S |
- |
- |
S |
S |
Days_Fee |
S |
S |
- |
- |
S |
S |
Days_Pay |
S |
S |
- |
- |
S |
S |
Num_Policy |
S |
S |
- |
- |
S |
S |
My_Policy |
S |
S |
S |
S |
S |
S |
Pays_Policy |
S |
S |
- |
- |
S |
S |
Sum_FeeYes |
S |
S |
- |
- |
S |
S |
Sum_FeeNo |
S |
S |
- |
- |
S |
S |
для администратора:
grant select, insert, update, delete on InsurerOrg to admin;
grant select, insert, update, delete on Insurer to admin;
grant select, insert, update, delete on worker_SK to admin;
grant select, insert, update, delete on put_money to admin;
grant select, insert, update, delete on Payment to admin;
grant select, insert, update, delete on percent to admin;
grant select, insert, update, delete on Insured to admin;
grant select, insert, update, delete on Work_policy to admin;
grant select, insert, update, delete on policy to admin;
grant select, insert, update, delete on Beneficiary to admin;
grant select on Curr_Policy to admin;
grant select on Days_Policy to admin;
grant select on Days_Fee to admin;
grant select on Days_Pay to admin;
grant select on Num_Policy to admin;
grant select on My_Policy to admin;
grant select on Pays_Policy to admin;
grant select on Sum_FeeYes to admin;
grant select on Sum_FeeNo to admin;
для Должностных лиц СК:
grant select on InsurerOrg to WorkSK;
grant select, insert, update, delete on Insurer to WorkSK;
grant select on worker_SK to WorkSK;
grant select on put_money to WorkSK;
grant select on Payment to WorkSK;
grant select on percent to WorkSK;
grant select, insert, update, delete on Insured to WorkSK;
grant select, insert, update on Work_policy to WorkSK;
grant select, insert, update, delete on policy to WorkSK;
grant select, insert, update, delete on Beneficiary to WorkSK;
grant select, insert, update, delete on Curr_Policy to WorkSK;
grant select on Days_Policy to WorkSK;
grant select on Days_Fee to WorkSK;
grant select on Days_Pay to WorkSK;
grant select on Num_Policy to WorkSK;
grant select on My_Policy to WorkSK;
grant select on Pays_Policy to WorkSK;
grant select on Sum_FeeYes to WorkSK;
grant select on Sum_FeeNo to WorkSK;
для Начальства СК:
grant select, insert, update, delete on InsurerOrg to Director;
grant select on Insurer to Director;
grant grant select, insert, update, delete on worker_SK to Director;
grant select on put_money to Director;
grant select on Payment to Director;
grant select on percent to Director;
grant select, on Insured to Director;
grant select, insert, update, delete on Work_policy to Director;
grant select on policy to Director;
grant select on Beneficiary to Director;
grant select on Curr_Policy to Director;
grant select on Days_Policy to Director;
grant select on Days_Fee to Director;
grant select on Days_Pay to Director;
grant select on Num_Policy to Director;
grant select on My_Policy to Director;
grant select on Pays_Policy to Director;
grant select on Sum_FeeYes to Director;
grant select on Sum_FeeNo to Director;
для Страхователя, Застрахованного, Выгодоприобретатель:
grant select on My_Policy to InsurerPerson, InsuredPerson, BenPerson;
grant select on InsurerOrg to PaySK;
для Бухгалтерии СК:
grant select on InsurerOrg to PaySK;
grant select on Insurer to PaySK;
grant select on worker_SK to PaySK;
grant select, insert, update, delete on put_money to PaySK;
grant select, insert, update, delete on Payment to PaySK;
grant select, insert, update, delete on percent to PaySK;
grant select on Insured to PaySK;
grant select on Work_policy to PaySK;
grant select on policy to PaySK;
grant select on Beneficiary to PaySK;
grant select on Curr_Policy to PaySK;
grant select on Days_Policy to PaySK;
grant select on Days_Fee to PaySK;
grant select on Days_Pay to PaySK;
grant select on Num_Policy to PaySK
grant select on My_Policy to PaySK;
grant select on Pays_Policy to PaySK;
grant select on Sum_FeeYes to PaySK;
grant select on Sum_FeeNo to PaySK;