Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабораторные работы (А-13-07) / Алехин, Макашова / Макашова_Алехин_Лабораторная_работа_7

.doc
Скачиваний:
41
Добавлен:
28.06.2014
Размер:
99.33 Кб
Скачать

Лабораторная работа 7

Вариант № 1

Выполнили студенты группы А-13-07

Макашова Мария

Алехин Роман

Задание:

  1. Создать контрольные ограничения на уровне поля, описанные выше, для вашей информационной таблицы в вашей БД;

create table uzb1

(nomer integer check (nomer between 1 and 700000),

fio char (40) not null check (fio not like '%.%' or fio not like '%-%'),

d_rogd char(2) check (d_rogd between '01' and '31'),

m_rogd char(2) check (m_rogd between '01' and '12'),

g_rogd char(2) check (g_rogd between '00' and '99'),

pol char(1) check (pol like 'M' or pol like 'Ж'),

sem_polog_k char(1) check (sem_polog_k in ('0', '1', '2', '3')),

spec char(6) check (spec between '000000' and '190046'),

kat_obuch_k char(2) check (kat_obuch_k between '01' and '17'),

vuz_k integer check (vuz_k between 128955 and 8199999),

mp char(2) check (mp between '01' and '12'),

gp char(2) check (gp between '00' and '99'),

mo char(2) check (mo between '01' and '12'),

gok char(2) check (gok between '00' and '99'))

insert into uzb1

(nomer,fio,d_rogd ,m_rogd,g_rogd)

values

(convert(integer,1), 'Сергеев Сергей Сергеевич', '12', '03', '70')

insert into uzb1

(nomer,fio,d_rogd ,m_rogd,g_rogd)

values

(convert(integer,2), 'Анатольев Анатолий Анатольевич', '32', '03', '70')

Msg 547, Level 16, State 0, Line 1

The INSERT statement conflicted with the CHECK constraint "CK__uzb1__d_rogd__3A81B327". The conflict occurred in database "AlekhinRV", table "dbo.uzb1", column 'd_rogd'.

The statement has been terminated.

  1. Создать следующие контрольные ограничения на уровне таблицы:

  1. значение поля «Год рождения» меньше значения поля «Год приема», которое, в свою очередь, меньше значения поля «Год окончания»;

  2. если значение поля «Код категории обучения» равно ‘07’, ‘08’ или ‘09’ (аспирант, аспирант-заочник или ординатура), то первые два символа в значении поля «Специальность» больше ‘00’; в остальных случаях (по всем другим значениям поля «Код категории обучения») первые два символа значения поля «Специальность» равны ‘00’;

  3. если значение поля «Пол» равно «Ж», то фамилия в поле «Фамилия Имя Отчество» должна заканчиваться на букву «А», иначе, если значение поля «Пол» равно «М», то фамилия в поле «Фамилия Имя Отчество» не должна заканчиваться на букву «А»;

create table uzb2

(nomer integer check (nomer between 1 and 700000),

fio char (40) not null check (fio not like '%.%' or fio not like '%-%'),

d_rogd char(2) check (d_rogd between '01' and '31'),

m_rogd char(2) check (m_rogd between '01' and '12'),

g_rogd char(2) check (g_rogd between '00' and '99'),

pol char(1) check (pol like 'М' or pol like 'Ж'),

sem_polog_k char(1) check (sem_polog_k in ('0', '1', '2', '3')),

spec char(6) check (spec between '000000' and '190046'),

kat_obuch_k char(2) check (kat_obuch_k between '01' and '17'),

vuz_k integer check (vuz_k between 128955 and 8199999),

mp char(2) check (mp between '01' and '12'),

gp char(2) check (gp between '00' and '99'),

mo char(2) check (mo between '01' and '12'),

gok char(2) check (gok between '00' and '99'),

constraint god_const check

(

(convert (integer, gp) > convert (integer, g_rogd)) and

(convert (integer, gok) > convert (integer, gp))

),

constraint kat_obuch_const check

(

((kat_obuch_k in ('07', '08', '09')) and

(spec not like '00%'))

or

((kat_obuch_k not in ('07', '08', '09')) and

(spec like '00%'))

),

constraint pol_const check

(

((pol = 'Ж') and

(fio like '%а % %'))

or

((pol = 'М') and

(fio not like '%а % %'))

)

A.)

insert into uzb2 (fio, g_rogd, gp, gok) values ('Владимирский Владимир Владимирович', '70', '69', '68')

Msg 547, Level 16, State 0, Line 2

The INSERT statement conflicted with the CHECK constraint "god_const". The conflict occurred in database "AlekhinRV", table "dbo.uzb2".

The statement has been terminated.

insert into uzb2 (fio, g_rogd, gp,gok) values ('Владимирский Владимир Владимирович', '70', '90', '95')

B.)

insert into uzb2 (fio,kat_obuch_k,spec) values ('Иванов Иван иванович', '08', '001234')

Msg 547, Level 16, State 0, Line 2

The INSERT statement conflicted with the CHECK constraint "kat_obuch_const". The conflict occurred in database "AlekhinRV", table "dbo.uzb2".

The statement has been terminated.

insert into uzb2 (fio,kat_obuch_k,spec) values ('Иванов Иван иванович', '08', '011234')

insert into uzb2 (fio,kat_obuch_k,spec) values ('Семёнов Семён Семёнович', '01', '031234')

Msg 547, Level 16, State 0, Line 2

The INSERT statement conflicted with the CHECK constraint "kat_obuch_const". The conflict occurred in database "AlekhinRV", table "dbo.uzb2".

The statement has been terminated.

insert into uzb2 (fio,kat_obuch_k,spec) values ('Семёнов Семён Семёнович', '01', '001234')

C.)

insert into uzb2 (fio,pol) values ('Петров Пётр Петрович', 'М')

insert into uzb2 (fio,pol) values ('Петрова Пётр Петрович', 'М')

Msg 547, Level 16, State 0, Line 2

The INSERT statement conflicted with the CHECK constraint "pol_const". The conflict occurred in database "AlekhinRV", table "dbo.uzb2".

The statement has been terminated.

insert into uzb2 (fio,pol) values ('Петрова Пётр Петрович', 'Ж')

insert into uzb2 (fio,pol) values ('Петров Пётр Петрович', 'Ж')

Msg 547, Level 16, State 0, Line 2

The INSERT statement conflicted with the CHECK constraint "pol_const". The conflict occurred in database "AlekhinRV", table "dbo.uzb2".

The statement has been terminated.

  1. Создать правило для вашей информационной таблицы, описанное выше.

create rule rule1 as @kat_obuch in ('01', '02', '03', '04', '05', '07', '08', '10', '11', '17')

sp_bindrule 'rule1', 'uzb1.[kat_obuch_k]'

insert into uzb1 (fio,kat_obuch_k) values ('Иванов Иван Иванович’, '09')

Msg 513, Level 16, State 0, Line 1

A column insert or update conflicts with a rule imposed by a previous CREATE RULE statement. The statement was terminated. The conflict occurred in database 'AlekhinRV', table 'dbo.uzb1', column 'kat_obuch_k'.

The statement has been terminated.

insert into uzb1 (fio,kat_obuch_k) values ('Иванов Иван Иванович’, '08')

  1. Создать своё ограничение.

create rule rule2

as @sem_polog_k in ('0', '1')

sp_bindrule 'rule2', 'uzb2.[sem_polog_k]'

insert into uzb2 (fio,sem_polog_k) values ('Петров Пётр Петрович', '3')

Msg 513, Level 16, State 0, Line 1

A column insert or update conflicts with a rule imposed by a previous CREATE RULE statement. The statement was terminated. The conflict occurred in database 'AlekhinRV', table 'dbo.uzb1', column 'sem_polog_k'.

The statement has been terminated.

insert into uzb2 (fio,sem_polog_k) values ('Петров Пётр Петрович', '1')