Скачиваний:
12
Добавлен:
20.01.2023
Размер:
119.14 Кб
Скачать

Министерство образования Республики Беларусь

Учреждение образования

«Белорусский государственный университет информатики и

радиоэлектроники»

Кафедра экономической информатики

Отчет

по лабораторной работе №2

«Проектирование базы данных»

по курсу «Системы и методы управления базами данных»

Вариант 5

Выполнил

студент гр. 972303: Евдокимов Р.Д.

Проверил: Воробей К.П.

Минск 2022

Цель работы:

Познакомиться с основными принципами создания базы данных в MS SQL Server. Изучить операции, проводимые с базами данных в целом. Получить навыки использования программы "SQL Server Management Studio" для создания, удаления, регистрации, подключения, извлечения метаданных, резервного копирования и восстановления базы данных. Изучить SQL-операторы для создания, подключения и удаления базы данных. Познакомиться с основными принципами управления учетными записями и ролями.

SQL-скрипт создания таблиц в базе данных

CREATE TABLE if not exists `client`

(

id_client bigint auto_increment

primary key,

last_name varchar(40) not null,

first_name varchar(40) not null,

father_name varchar(40) not null,

passport_data varchar(9) not null check (passport_data LIKE '[A-Z][A-Z][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),

date_birth date,

address varchar(40),

city varchar(40),

phone varchar(40) check (phone LIKE '+375-[2-4][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9][0-9]')

);

CREATE TABLE if not exists type_house

(

id_type_house bigint auto_increment

primary key,

`name` varchar(50) not null,

category_house varchar(50) not null,

`description` varchar(200),

price decimal(5,2) not null

);

CREATE TABLE if not exists resort_hotel

(

id_resort_hotel bigint auto_increment

primary key,

id_type_house bigint not null,

`name` varchar(50) not null,

address varchar(50) not null,

city varchar(50) not null,

country varchar(50) not null,

phone varchar(15) not null,

`description` varchar(200),

count_room int,

swimming_pool bool,

med_services bool not null,

spa_salon bool,

`level` int not null,

destination int,

foreign key (id_type_house) references type_house(id_type_house)

);

CREATE TABLE tour

(

id_tour bigint auto_increment

primary key,

id_type_house bigint not null,

`name` varchar(50) not null,

transport_type varchar(50) not null,

meals_types varchar(20) not null check (meals_types in ('одноразовое', 'двухразовое', 'трехразовое', 'завтраки')),

price decimal(5,2) not null,

foreign key (id_type_house) references type_house(id_type_house)

);

CREATE TABLE trip

(

id_trip bigint auto_increment

primary key,

id_resort_hotel bigint not null,

id_type_house bigint not null,

date_arrivial date not null,

date_departure date not null,

children bool not null,

med_insurance bool,

count_people int,

price decimal(5,2) not null,

foreign key (id_type_house) references type_house(id_type_house),

foreign key (id_resort_hotel) references resort_hotel(id_resort_hotel)

);

CREATE TABLE order_trip

(

id_order_trip bigint auto_increment

primary key,

id_trip bigint not null,

id_client bigint not null,

foreign key (id_trip) references trip(id_trip),

foreign key (id_client) references `client`(id_client)

);

CREATE TABLE order_tour

(

id_order_trip bigint auto_increment

primary key,

id_tour bigint not null,

id_client bigint not null,

count_days bigint not null,

foreign key (id_tour) references tour(id_tour),

foreign key (id_client) references `client`(id_client)

);

SQL-скрипт создания ролей

CREATE USER "administartor"@"localhost" IDENTIFIED BY "admin";

CREATE USER "client"@"localhost" IDENTIFIED BY "client";

CREATE USER "tour_agent"@"localhost" IDENTIFIED BY "tour-agent";

grant all on `client` to "administartor"@"localhost";

grant insert, update on `client` to "client"@"localhost";

grant all on order_tour to "administartor"@"localhost";

grant select, insert, update on order_tour to "client"@"localhost";

grant select, insert, update on order_tour to "tour_agent"@"localhost";

grant all on order_trip to "administartor"@"localhost";

grant select, insert, update on order_trip to "client"@"localhost";

grant select, insert, update on order_trip to "tour_agent"@"localhost";

grant all on resort_hotel to "administartor"@"localhost";

grant select on resort_hotel to "client"@"localhost";

grant select on resort_hotel to "tour_agent"@"localhost";

grant all on tour to "administartor"@"localhost";

grant select on tour to "client"@"localhost";

grant select on tour to "tour_agent"@"localhost";

grant all on trip to "administartor"@"localhost";

grant select on trip to "client"@"localhost";

grant select on trip to "tour_agent"@"localhost";

grant all on type_house to "administartor"@"localhost";

grant select on type_house to "client"@"localhost";

grant select on type_house to "tour_agent"@"localhost";

Список сущностей

Соседние файлы в предмете Системы и Методы Управления Базами Данных