Логическое проектирование и реализация реляционных баз данных. Основы Transact-SQL (Пример выполнения лабораторной работы), страница 2

id_train

Train_name

Train_type

Train_number

1

Смена

фирменный

25

2

Смена

фирменный

26

3

Николаевский экспресс

фирменный

5

4

Николаевский экспресс

фирменный

6

5

Красная стрела

фирменный

1

6

Красная стрела

фирменный

2

7

Аврора

фирменный

159

8

Аврора

фирменный

160

По результату выборки можно установить идентификатор (id_train) конкретного поезда, чтобы правильно ссылаться на него из других таблиц – например, из coaches.

3. Вставка в таблицу coaches и просмотр содержимого

--Вагоны(номер, тип, поезд)

insert into coaches values(1, 'Купе', 1)

insert into coaches values(2, 'Купе', 1)

insert into coaches values(3, 'Купе', 1)

insert into coaches values(4, 'Купе', 1)

insert into coaches values(5, 'Купе', 1)

insert into coaches values(6, 'Купе', 1)

insert into coaches values(7, 'Купе', 1)

insert into coaches values(8, 'СВ', 1)

insert into coaches values(9, 'Купе', 1)

insert into coaches values(10, 'Купе', 1)

insert into coaches values(11, 'Купе', 1)

insert into coaches values(12, 'Купе', 1)

insert into coaches values(13, 'Купе', 1)

insert into coaches values(14, 'Купе', 1)

insert into coaches values(15, 'Купе', 1)

insert into coaches values(16, 'Купе', 1)

insert into coaches values(17, 'Купе', 1)

insert into coaches values(18, 'Купе', 1)

insert into coaches values(1, 'Купе', 2)

insert into coaches values(2, 'Купе', 2)

insert into coaches values(3, 'Купе', 2)

insert into coaches values(4, 'Купе', 2)

insert into coaches values(5, 'Купе', 2)

insert into coaches values(6, 'Купе', 2)

insert into coaches values(7, 'Купе', 2)

insert into coaches values(8, 'СВ', 2)

insert into coaches values(9, 'Купе', 2)

insert into coaches values(10, 'Купе', 2)

insert into coaches values(11, 'Купе', 2)

insert into coaches values(12, 'Купе', 2)

insert into coaches values(13, 'Купе', 2)

insert into coaches values(14, 'Купе', 2)

insert into coaches values(15, 'Купе', 2)

insert into coaches values(16, 'Купе', 2)

insert into coaches values(17, 'Купе', 2)

insert into coaches values(18, 'Купе', 2)

Результат:

(1 row(s) affected)

select * from coaches

Результат:

id_coach

coach _number

coach_type

Id_train

1

1

Купе

1

2

2

Купе

1

3

3

Купе

1

4

4

Купе

1

5

5

Купе

1

31

13

Купе

2

32

14

Купе

2

33

15

Купе

2

34

16

Купе

2

35

17

Купе

2

36

18

Купе

2

4. Заполнение таблицы stations и отображение результатов

--Станции(название)

insert into stations values('Санкт-Петербург')

insert into stations values('Мал. Вишера')

insert into stations values('Бологое')

insert into stations values('В. Волочек')

insert into stations values('Тверь')

insert into stations values('Москва')

Результат:

(1 row(s) affected)

select * from stations

Результат:

Id_station

st_name

1

Санкт-Петербург

2

Мал. Вишера

3

Бологое

4

В. Волочек

5

Тверь

6

Москва

5. Заполнение таблицы seats и её просмотр

--места

insert into seats values(1, 'н', 1)

insert into seats values(2, 'в', 1)

insert into seats values(3, 'н', 1)

insert into seats values(4, 'в', 1)

insert into seats values(5, 'н', 1)

insert into seats values(6, 'в', 1)

insert into seats values(7, 'н', 1)

insert into seats values(8, 'в', 1)

insert into seats values(9, 'н', 1)

insert into seats values(10, 'в', 1)

insert into seats values(11, 'н', 1)

insert into seats values(12, 'в', 1)

insert into seats values(13, 'н', 1)

insert into seats values(14, 'в', 1)

insert into seats values(15, 'н', 1)

insert into seats values(16, 'в', 1)

insert into seats values(17, 'н', 1)

insert into seats values(18, 'в', 1)

insert into seats values(19, 'н', 1)

insert into seats values(20, 'в', 1)

insert into seats values(21, 'н', 1)

insert into seats values(22, 'в', 1)

insert into seats values(23, 'н', 1)

insert into seats values(24, 'в', 1)

insert into seats values(25, 'н', 1)