· 8 years ago · Nov 26, 2017, 08:30 PM
1set dateformat dmy
2use master
3go
4if exists (select 'true' from sys.databases
5 where name='spital')
6 BEGIN
7 alter database spital set single_user with rollback immediate
8 drop database spital
9 END
10go
11create Database spital
12go
13--crearea structurii tabelelor
14use spital
15go
16CREATE TABLE Proceduri (
17IdProcedura int primary key NOT NULL ,
18TipProcedura char(80) NOT NULL ,
19NrLaborator int NOT NULL ,
20DataProcedura date NOT NULL
21)
22GO
23CREATE TABLE Diagnoza (
24IdDiagnoza int primary key NOT NULL ,
25TipDiagnoza char(30) NOT NULL ,
26IdProcedura int NOT NULL
27)
28GO
29CREATE TABLE FisaMedicala (
30IdFisMed int primary key NOT NULL ,
31IdMed int NOT NULL ,
32Dataintern date NOT NULL ,
33Dataexterna date NOT NULL ,
34IdAsigurare int NOT NULL ,
35IdDiagnoza int NOT NULL
36)
37GO
38CREATE TABLE Pacieti (
39IdPacient int primary key NOT NULL ,
40IdFisMed int NOT NULL ,
41Nume char(30) NOT NULL ,
42Pren char(30) NOT NULL ,
43DataNas date NOT NULL ,
44IdAdresa int NOT NULL
45)
46GO
47CREATE TABLE Adresa (
48IdAdresa int primary key NOT NULL ,
49NumeSect char(30) NOT NULL ,
50NrStrada char(30) NOT NULL
51)
52GO
53CREATE TABLE Medici (
54IdMed int primary key NOT NULL ,
55NumeMed char(30) NOT NULL ,
56PrenMed char(30) NOT NULL ,
57IdAdresa int NOT NULL ,
58NrTell char(12) NOT NULL
59)
60GO
61ALTER TABLE Diagnoza ADD FOREIGN KEY (IdProcedura) REFERENCES Proceduri (IdProcedura) ON DELETE NO ACTION ON UPDATE NO ACTION
62GO
63ALTER TABLE FisaMedicala ADD FOREIGN KEY (IdDiagnoza) REFERENCES Diagnoza (IdDiagnoza) ON DELETE NO ACTION ON UPDATE NO ACTION
64GO
65ALTER TABLE Pacieti ADD FOREIGN KEY (IdFisMed) REFERENCES FisaMedicala (IdFisMed) ON DELETE NO ACTION ON UPDATE NO ACTION
66GO
67ALTER TABLE Pacieti ADD FOREIGN KEY (IdAdresa) REFERENCES Adresa (IdAdresa) ON DELETE NO ACTION ON UPDATE NO ACTION
68GO
69ALTER TABLE Medici ADD FOREIGN KEY (IdAdresa) REFERENCES Adresa (IdAdresa) ON DELETE NO ACTION ON UPDATE NO ACTION
70GO
71ALTER TABLE FisaMedicala ADD FOREIGN KEY (IdMed) REFERENCES Medici (IdMed) ON DELETE NO ACTION ON UPDATE NO ACTION
72GO
73INSERT INTO Adresa(IdAdresa, NumeSect, NrStrada) VALUES
74(N'11', N'Centru', N'Florilor'),
75(N'12', N'Botanica', N'Trandafirilor'),
76(N'13', N'Ciocana', N'Columna'),
77(N'14', N'Telecentru', N'Izmail'),
78(N'15', N'Ciocana', N'Bulgara')
79go
80INSERT INTO Proceduri(IdProcedura, TipProcedura, NrLaborator ,DataProcedura) VALUES
81(N'1', N'Procedura de triaj epidemiologic', N'101', N'2017-06-20'),
82(N'2', N'Procedura ambulatoriu integrat.', N'103', N'2017-06-24'),
83(N'3', N'Procedura consulturi interdiscplinare', N'105', N'2017-07-22'),
84(N'4', N'Procedura mobilizare a pacientului', N'106', N'2017-05-23'),
85(N'5', N'Procedura investigatii', N'109', N'2017-02-20')
86go
87INSERT INTO Diagnoza(IdDiagnoza, TipDiagnoza, IdProcedura) VALUES
88(N'11', N'buna', N'1'),
89(N'12', N'rea', N'2'),
90(N'13', N'foarte rea', N'3'),
91(N'14', N'buna', N'4'),
92(N'15', N'buna', N'5')
93go
94INSERT INTO Medici(IdMed, NumeMed, PrenMed, IdAdresa, NrTell) VALUES
95(N'1', N'Ion', N'Tarsana', N'15', N'069785512'),
96(N'2', N'Valera', N'Marandici', N'11', N'069733512'),
97(N'3', N'Vitalie', N'Ceoban', N'14', N'069768912'),
98(N'4', N'Costatin', N'Costatin', N'13', N'069002212'),
99(N'5', N'Ion', N'Butuc', N'12', N'069555512')
100go
101INSERT INTO FisaMedicala(IdFisMed, IdMed, Dataintern, Dataexterna, IdAsigurare, IdDiagnoza) VALUES
102(N'1', N'1', N'2017-06-21', N'2017-01-20', N'5123124', N'11'),
103(N'2', N'2', N'2017-05-25', N'2017-02-24', N'5124155', N'12'),
104(N'3', N'3', N'2017-03-12', N'2017-05-22', N'2352625', N'13'),
105(N'4', N'4', N'2017-01-22', N'2017-05-23', N'5235252', N'14'),
106(N'5', N'5', N'2017-02-10', N'2017-02-20', N'5235236', N'15')
107go
108INSERT INTO Pacieti(IdPacient, IdFisMed, Nume, Pren, DataNas, IdAdresa) VALUES
109(N'1', N'1', N'Ion', N'Mandea', N'2001-03-23', N'12'),
110(N'2', N'2', N'Vasile', N'Marar', N'2002-03-10', N'11'),
111(N'3', N'3', N'Ana', N'Zale', N'2001-04-09', N'13'),
112(N'4', N'4', N'Vera', N'Ureche', N'2000-12-25', N'15'),
113(N'5', N'5', N'Valentin', N'Maramures', N'2003-02-03', N'14')