13

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
USE master;
GO
IF db_id (N'lab131') IS NOT NULL
DROP DATABASE lab131;
GO
CREATE DATABASE lab131
ON (NAME = dat_lab131, FILENAME = 'C:\data\datlab131.mdf',
SIZE = 10MB, MAXSIZE = 50MB, FILEGROWTH = 5MB)
LOG ON (NAME = log_lab131, FILENAME = 'C:\data\loglab131.ldf',
SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB);
GO
IF db_id (N'lab132') IS NOT NULL
DROP DATABASE lab132;
GO
CREATE DATABASE lab132
ON (NAME = dat_lab132, FILENAME = 'C:\data\datlab132.mdf',
SIZE = 10MB, MAXSIZE = 50MB, FILEGROWTH = 5MB)
LOG ON (NAME = log_lab132, FILENAME = 'C:\data\loglab132.ldf',
SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB);
GO
USE lab131;
GO
CREATE TABLE Person (idofperson int PRIMARY KEY CHECK (idofperson < 100),
firstname char(50) NOT NULL,
secondname char(50) NOT NULL);
GO
USE lab132;
GO
CREATE TABLE Person (idofperson int PRIMARY KEY CHECK (idofperson >= 100),
firstname char(50) NOT NULL,
secondname char(50) NOT NULL);
GO
USE master;
GO
CREATE VIEW view_Person_131_132
AS
SELECT * FROM lab131.dbo.Person UNION ALL SELECT * FROM lab132.dbo.Person;
GO
INSERT view_Person_131_132 (idofperson, firstname, secondname) VALUES
(1, 'Regina', 'Frank'),
(2, 'Lola', 'Moon'),
(3, 'James', 'Cost'),
(200, 'James', 'Cost');
GO
DELETE view_Person_131_132 WHERE idofperson = 2;
GO
UPDATE view_Person_131_132 SET idofperson = 201 WHERE idofperson = 3;
GO
SELECT * FROM view_Person_131_132;
GO
SELECT * FROM lab131.dbo.Person;
GO
SELECT * FROM lab132.dbo.Person;
GO
DROP VIEW view_Person_131_132;
DROP TABLE lab131.dbo.Person;
DROP TABLE lab132.dbo.Person;
DROP DATABASE lab131;
DROP DATAbASE lab132;
GO