Автор: Пользователь скрыл имя, 19 Декабря 2010 в 23:01, курсовая работа
В ходе выполнения курсового проекта была разработана база данных «СКЛАД». В базе данных учтены данные об сущностях, которые описывают иерархию товара, покупателя (продавца), приходных (расходных) накладных, место на складе. В основе создания базы данных лежит задание, полученное на кафедре «Информатика и интеллектуальная собственность».
1. Вступление.	2
2. Индивидуальное задание.	3
3. Построение инфологической модели данных.	4
4. Построение концептуальной модели данных.	6
5. Построение физической модели и создание базы данных.	7
6. Создание процедурных ограничений целостности.	10
7. Создание типичных запросов к базе данных.	11
7.1. Примеры операторов, которые записывают данные в таблицы	11
7.2. Примеры операторов на выборку данных из базы данных	13
7.3. Проверка ограничений целостности	15
Приложение А. SQL-скрипты создания таблиц базы данных	16
Приложение Б. SQL-скрипты создания триггеров	20
Приложение В. Полные выборки таблиц.	21
and success='no'
and date_1='19.01.2009'
Результат выборки:
5. Список договоров по продаже, которые выполнены на заданную дату 31.12.2008.
select saleorder_id,s.salesman_id,s.
from salesman s,sale_order o
where s.salesman_id=o.salesman_id
and success='yes'
and date_1='31.12.2008'
Результат выборки:
6. Список мест на складе на которые можно разместить товар заданного типа.
select p.place_id from place p,maxonplace,product pr
where pr.product_id=p.product_id
and max>p.quantity
and product_name='Пшеница'
Результат выборки:
 
 
 
7.3. Проверка ограничений целостности.
    Для 
проверки триггера выполним запросы, первый 
будет вставлять и изменять записи 
в таблице расходной накладной на значение 
количества товара, превышающее количество 
на складе . 
update spendon set quantity=2001 where product_id=3
------------------------------ 
Введенные команды ------------
update spendon set quantity=2001 where product_id=3;
------------------------------
update spendon set quantity=2001 where product_id=3
DB21034E Данная команда обрабатывалась как оператор SQL, поскольку она не
является допустимой командой процессора командной строки. При обработке SQL
было получено сообщение:
SQL0438N Программа генерирует ошибку с текстом диагностики: "Изъятого товара не может быть больше чем на складе".
SQLSTATE=75000 
insert into 
spendon values(5,3,2001); 
------------------------------ Введенные команды ----------------------------
insert into spendon values(5,3,2001);
------------------------------
insert into spendon values(5,3,2001)
DB21034E Данная команда обрабатывалась как оператор SQL, поскольку она не
является допустимой командой процессора командной строки. При обработке SQL
было получено сообщение:
SQL0438N Программа генерирует ошибку с текстом диагностики: "Изъятого товара не может быть больше чем на складе".
SQLSTATE=75000  
 
Приложение А. SQL-скрипты создания таблиц базы данных.
create table db2admin.customer(
customer_id integer not null,
name varchar(45) not null,
address varchar(45) not null,
phone_number integer not null,
primary key (customer_id)
); 
 
create table db2admin.product(
product_id integer not null,
product_name varchar(45) not null,
quantity integer,
cover varchar(45) not null,
comments varchar(500),
primary key (product_id)
); 
 
create table db2admin.salesman(
salesman_id integer not null,
name varchar(45) not null,
address varchar(45) not null,
phone_number integer not null,
primary key (salesman_id)
); 
 
create table db2admin.place(
place_id integer not null,
product_id integer not null,
quantity integer not null,
size decimal(4,2) not null,
primary key (place_id),
foreign key (product_id) REFERENCES db2admin.product(product_id)
); 
 
create table db2admin.customer_order(
cusorder_id integer not null,
customer_id integer not null,
date_1 date not null,
date_2 date not null,
success varchar(4) not null,
primary key (cusorder_id),
foreign key (customer_id) references db2admin.customer(customer_id)
); 
 
create table db2admin.bye(
cusorder_id integer not null references 
db2admin.customer_order(
ON DELETE CASCADE ON UPDATE RESTRICT,
product_id integer not null references db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
primary key (cusorder_id, product_id)
); 
 
create table db2admin.maxonplace(
product_id integer not null references db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
place_id integer not null references db2admin.place(place_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
max integer not null,
primary key (product_id, place_id)
); 
 
create table db2admin.spend(
spend_id integer not null,
cusorder_id integer not null,
date date not null,
primary key (spend_id),
foreign key (cusorder_id) references 
db2admin.customer_order(
); 
 
create table db2admin.spendon(
spend_id integer not null REFERENCES db2admin.spend(spend_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
product_id integer not null references db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
quantity integer not null,
primary key (spend_id, product_id)
); 
 
create table db2admin.take(
spend_id integer not null REFERENCES db2admin.spend(spend_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
product_id integer not null REFERENCES db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
place_id integer not null,
primary key (spend_id, product_id),
foreign key (place_id) references db2admin.place(place_id)
); 
 
create table db2admin.sale_order(
saleorder_id integer not null,
salesman_id integer not null,
date_1 date not null,
date_2 date not null,
success varchar(4) not null,
primary key (saleorder_id),
foreign key (salesman_id) references db2admin.salesman(salesman_id)
); 
 
create table db2admin.saleones(
product_id integer not null REFERENCES db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
saleorder_id integer not null REFERENCES 
db2admin.sale_order(saleorder_
ON DELETE CASCADE ON UPDATE RESTRICT,
quantity integer not null,
primary key (product_id, saleorder_id)
); 
 
create table db2admin.incash(
come_id integer not null,
saleorder_id integer not null,
date date not null,
primary key (come_id),
foreign key (saleorder_id) references 
db2admin.sale_order(saleorder_
); 
 
create table db2admin.incashon(
product_id integer not null REFERENCES db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
come_id integer not null REFERENCES db2admin.incash(come_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
quantity integer not null,
primary key (product_id, come_id)
); 
 
create table db2admin.placing_incash(
come_id integer not null REFERENCES db2admin.incash(come_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
product_id integer not null REFERENCES db2admin.product(product_id)
ON DELETE CASCADE ON UPDATE RESTRICT,
place_id integer not null,
quantity integer not null,
primary key (come_id, product_id),
foreign key (place_id) references db2admin.place(place_id)
); 
 
 
Приложение Б. SQL-скрипты создания триггеров.
create trigger nedostach no cascade before insert on spendon
referencing new as neww
for each row mode db2sql
when(
neww.quantity > (select sum(quantity) from place
where product_id=neww.product_id )
)
signal sqlstate 
'75000'('Изъятого товара не может быть больше 
чем на складе'); 
 
 
create trigger nedostach1 no cascade before update on spendon
referencing new as neww
for each row mode db2sql
when(
neww.quantity > (select sum(quantity) from place
where product_id=neww.product_id )
)
signal sqlstate 
'75000'('Изъятого товара не может быть больше 
чем на складе'); 
 
 
Приложение В. Полные выборки таблиц.
select * from customer
select * from customer_order
select * from bye
select * from spend
select * from spendon
select * from take
select * from salesman
select * from place
select * from maxonplace
select * from sale_order
select * from saleones
select * from incash
select * from incashon
select * from placing_incash