2.1 Создание объектов базы данных
Создание таблицы Данные о сотруднике
create table DannyeOSotrydnike
(DOS_id int identity not null,
FIO char (70) not null,
PRIMARY KEY (DOS_id));
Создание таблицы Место дежурства
create table MestoDejyrstva
(MD_id int identity not null,
MD char (70) not null,
PRIMARY KEY (MD_id));
создание таблицы СОТРУДНИК
create table Sotrydnik (S_ID int identity primary key not null, DOS_id int foreign key references DannyeOSotrydnike (DOS_id) not null, MD_id int foreign key references MestoDejyrstva (MD_id) not null);
Создание таблицы отделение ГИБДД
create table Otdelenie_GIBDD
(OGIBDD_id int identity not null,
NazvanieO char (70) not null,
KolichestvoSotrydnikov int not null,
PRIMARY KEY (OGIBDD_id));
Создание таблицы Водитель
create table VODITEL
(Voditel_id int identity not null,
VoditelFIO char (70) not null,
DataRogdeniya date not null,
PRIMARY KEY (Voditel_id));
Создание таблицы ВЛАДЕЛЕЦ
create table VLADELEC
(Vladelec_id int identity primary key not null,
Voditel_id int foreign key references VODITEL (Voditel_id) not null,
NomerPrav char(6) not null);
Создание таблицы Модель
create table MODEL
(Model_id int identity not null,
Model char (80) not null,
PRIMARY KEY (Model_id));
Создание таблицы Цвет
create table CVET
(Cvet_id int identity not null,
Cvet char (35) not null,
PRIMARY KEY (Cvet_id));
создание таблицы Автотранспорт
create table AVTO_TRANSPORT (AT_ID int identity primary key not null, Model_id int foreign key references MODEL (Model_id) not null, Cvet_id int foreign key references CVET(Cvet_id) not null);
Создание таблицы ТРАНСПОРТНОЕ СРЕДСТВО
create table Transportnoe_Sredstvo
(TS_id int identity primary key not null,
AT_ID int foreign key references AVTO_TRANSPORT (AT_ID) not null,
NumberTS char (7) not null);
Создание таблицы Вид нарушения
create table Vid_Narysheniya
(VN_id int identity not null,
VN char (80) not null,
PRIMARY KEY (VN_id));
Создание таблицы Нарушение
create table NARYSHENIE
(N_id int identity primary key not null,
VN_id int foreign key references Vid_Narysheniya (VN_id) not null,
shtraf char (77) not null);
Создание таблицы Протокол
create table PROTOCOL
(Protocol_id int identity primary key not null,
N_id int foreign key references NARYSHENIE(N_id) not null,
Data date not null);
-Создание таблицы Сотрудник-Отделение
|
create table Sotrydnik_Otdelenie (SO_ID int identity primary key not null, S_ID int foreign key references Sotrydnik (S_ID) not null,OGIBDD_id int foreign key references Otdelenie_GIBDD(OGIBDD_id) not null);
Создание таблицы Протокол-Сотрудник
create table PROTOCOL_Sotrydnik (PS_ID int identity primary key not null, S_ID int foreign key references Sotrydnik (S_ID) not null, Protocol_id int foreign key references PROTOCOL(Protocol_id) not null);
Создание таблицы Протокол-Владелец
create table PROTOCOL_VLADELEC (PV_ID int identity primary key not null, Protocol_id int foreign key references PROTOCOL(Protocol_id) not null, Vladelec_id int foreign key references VLADELEC (Vladelec_id) not null);
Создание таблицы Владелец-Транспортное средство
create table VLADELEC_Transportnoe_Sredstvo (VTS_ID int identity primary key not null, Vladelec_id int foreign key references VLADELEC (Vladelec_id) not null, TS_id int foreign key references Transportnoe_Sredstvo (TS_id) not null);
2.2 Схема базы данных(рис. схемы бд из SQL)
2.3 Разработка представлений(3 шт.)
--ФИО сотрудника, с кодом 2
CREATE VIEW FIO_Sotrydnika
as select FIO
from DannyeOSotrydnike
where DOS_id =2
--наименование вида нарушения с кодом 25
CREATE VIEW Naimenovanie_Narysheniya
As select VN
from Vid_Narysheniya
where VN_id =8
--Название и цвет автотранспорта с кодом >4
CREATE VIEW Naimenovanie_Cvet_AT
As select Model, Cvet
from AVTO_TRANSPORT, MODEL, CVET
where AVTO_TRANSPORT.Model_id= MODEL.Model_id and AVTO_TRANSPORT.Cvet_id=CVET.Cvet_id and AT_ID >4