· 6 years ago · Dec 16, 2019, 10:28 AM
1// file 1
2
3use master;
4go
5
6drop database if exists lab13_db_1;
7go
8
9create database lab13_db_1;
10go
11
12use lab13_db_1;
13go
14
15create table Client
16(
17 PassportID int primary key not null
18 check (PassportID between 1 and 2),
19 FullName varchar(50) not null,
20 Birthday datetime not null,
21 Sex varchar(1) not null
22);
23go
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44// file 2
45
46use master;
47go
48
49drop database if exists lab13_db_2;
50go
51
52create database lab13_db_2;
53go
54
55use lab13_db_2;
56go
57
58create table Client
59(
60 PassportID int primary key not null
61 check (PassportID between 3 and 4),
62 FullName varchar(50) not null,
63 Birthday datetime not null,
64 Sex varchar(1) not null
65);
66go
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82// file 3
83
84use master;
85go
86
87drop database if exists lab13_db_union;
88go
89
90create database lab13_db_union;
91go
92
93use lab13_db_union;
94go
95
96create view All_Clients
97as
98select *
99from lab13_db_1.dbo.Client
100union all
101select *
102from lab13_db_2.dbo.Client;
103go
104
105
106insert into All_Clients(PassportID, FullName, Birthday, Sex)
107values (1, 'FullName_1', '2011-01-01', 'M'),
108 (2, 'FullName_2', '2012-01-01', 'F');
109
110insert into All_Clients(PassportID, FullName, Birthday, Sex)
111values (3, 'FullName_3', '2013-01-01', 'M'),
112 (4, 'FullName_4', '2014-01-01', 'F');
113
114select *
115from All_Clients;
116
117select *
118from lab13_db_1.dbo.Client;
119
120select *
121from lab13_db_2.dbo.Client;
122
123update All_Clients
124set FullName = '0_o'
125where PassportID = 3;
126
127delete from All_Clients
128where PassportID = 1;
129
130select *
131from All_Clients;
132
133select *
134from lab13_db_1.dbo.Client;
135
136select *
137from lab13_db_2.dbo.Client;
138go