Advertisement
Guest User

Untitled

a guest
Aug 15th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.09 KB | None | 0 0
  1. create database PacijentDoktorPregled
  2.  
  3. use PacijentDoktorPregled
  4. go
  5.  
  6.  
  7.  
  8.  
  9. create table Pacijenti
  10. (
  11. PacijentID INT NOT NULL IDENTITY(1,1) CONSTRAINT PK_PacijentID PRIMARY KEY,
  12. JMBG nvarchar(13) not null constraint uq_jmbg unique,
  13. Prezime nvarchar(50) not null,
  14. Ime nvarchar(50) not null,
  15. DatumRodjenja date DEFAULT null,
  16. DatumKreiranja date not null DEFAULT GETDATE(),
  17. DatumModifikovanja date DEFAULT null
  18. )
  19.  
  20. create table OsobljeTitule
  21. (
  22. TitulaID int not null identity(1,1) constraint PK_TitulaID PRIMARY KEY,
  23. Naziv nvarchar(100) not null,
  24. DatumKreiranja date DEFAULT GETDATE(),
  25. DatumModifikovanja date DEFAULT null,
  26.  
  27.  
  28. )
  29.  
  30. create table Osoblje
  31. (
  32. OsobljeID INT NOT NULL IDENTITY(1,1) CONSTRAINT PK_OsobljeID PRIMARY KEY,
  33. TitulaID INT NOT NULL CONSTRAINT FK_TitulaID FOREIGN KEY REFERENCES OsobljeTitule(TitulaID),
  34. Prezime nvarchar(50) not null,
  35. Ime nvarchar(50) not null,
  36. DatumKreiranja date DEFAULT GETDATE(),
  37. DatumModifikovanja date DEFAULT null
  38. )
  39.  
  40. create table Pregled
  41. (
  42. PacijentID INT NOT NULL CONSTRAINT FK_PacijentID FOREIGN KEY REFERENCES Pacijenti(PacijentID),
  43. OsobljeID INT NOT NULL CONSTRAINT FK_OsobljeID FOREIGN KEY REFERENCES Osoblje(OsobljeID)
  44. CONSTRAINT PK_PacijentID_OsobljeID PRIMARY KEY(PacijentID,OsobljeID),
  45. PregledID INT NOT NULL,
  46. DatumPregleda date DEFAULT GETDATE(),
  47. Dijagnoza nvarchar(100) not null
  48.  
  49. )
  50.  
  51. ALTER TABLE Pregled
  52. ADD DatumKreiranja date DEFAULT GETDATE(),
  53. DatumModifikovanja date DEFAULT NULL
  54. GO
  55.  
  56.  
  57.  
  58. insert into Pacijenti(JMBG,Prezime,Ime,DatumRodjenja,DatumModifikovanja)
  59. Select LEFT( convert(nvarchar(255),NEWID()),13) AS JMBG,LastName,FirstName,BirthDate,Getdate()
  60. from Northwind.dbo.Employees
  61.  
  62. select*
  63. from Pacijenti
  64. drop database PacijentDoktorPregled
  65.  
  66. INSERT INTO OsobljeTitule (Naziv)
  67. VALUES ('Stomatolog'),
  68. ('Oftalmolog'),
  69. ('Ginekolog'),
  70. ('Pulmolog'),
  71. ('Onkolog')
  72.  
  73. select*
  74. from OsobljeTitule
  75.  
  76.  
  77. insert into Osoblje(TitulaID,Prezime,Ime)
  78. select TOP 2 3, au_lname,au_fname
  79. from pubs.dbo.authors
  80. ORDER BY NEWID()
  81.  
  82. select*
  83. from Osoblje
  84. go
  85. select * from Pregled
  86. create procedure usp_insert_pregled
  87.  
  88. @PacijentID INT,
  89. @OsobljeID INT,
  90. @PregledID INT,
  91. @DatumPregleda date,
  92. @Dijagnoza nvarchar(100),
  93. @DatumKreiranja date,
  94. @DatumModifikovanja date
  95. as
  96. begin
  97.  
  98. insert into Pregled
  99. values(@PacijentID,@OsobljeID,@PregledID,@DatumPregleda,@Dijagnoza,@DatumKreiranja,@DatumModifikovanja)
  100. end
  101.  
  102.  
  103. DECLARE @date date
  104. SET @date = Cast(getdate() as date)
  105. exec usp_insert_pregled 1,1,4,@date,'nesto',@date,null
  106. exec usp_insert_pregled 19,1,2,@date,'nesto',@date,null
  107.  
  108.  
  109.  
  110. SELECT*
  111. FROM Pregled
  112.  
  113. select * from Pacijenti
  114.  
  115. ALTER TABLE Pacijenti
  116. add email nvarchar(100) default null,
  117. lozinka nvarchar(100) default null
  118. create procedure p_pacijenti(
  119.  
  120. @email nvarchar(100),
  121. @lozinka nvarchar(100)
  122.  
  123.  
  124. )
  125. as
  126. begin
  127. update Pacijenti
  128. set email=Ime+Prezime+@email,
  129. lozinka=@lozinka
  130. where DatumModifikovanja is not null
  131. end
  132.  
  133. declare @email nvarchar(20)='@edu.fit.ba'
  134. declare @lozinka nvarchar(20)=left(newid(),12)
  135.  
  136.  
  137. exec p_pacijenti @email,@lozinka
  138.  
  139.  
  140.  
  141. drop procedure p_pacijenti
  142. select * from Pacijenti
  143.  
  144.  
  145. select * from Pacijenti
  146.  
  147. select * from Pacijenti
  148.  
  149.  
  150.  
  151.  
  152.  
  153. select p.Ime,p.Prezime,pp.Dijagnoza,o.Ime+o.Prezime+ot.Naziv as 'Doktor'
  154. from Pacijenti as p join Pregled as pp on p.PacijentID=pp.PacijentID
  155. join Osoblje as o on pp.OsobljeID=o.OsobljeID join OsobljeTitule as ot
  156. on ot.TitulaID=o.TitulaID
  157. where p.email like 'L%' or pp.Dijagnoza is not null
  158.  
  159. create nonclustered index ix_Pacijenti
  160. on Pacijenti(Ime,Prezime)
  161. include(email)---provjeri ovo ja msm da je uredu nisam siguran...
  162.  
  163.  
  164.  
  165. create procedure p_delete(
  166.  
  167. @PacijentID int
  168.  
  169. )
  170. as begin
  171.  
  172.  
  173. delete from Pacijenti where PacijentID=@PacijentID and
  174. PacijentID not in (select PacijentID from Pregled)
  175.  
  176.  
  177. end
  178.  
  179.  
  180.  
  181. drop procedure p_delete
  182. exec p_delete 31
  183. select * from Pacijenti
  184. select * from Pregled
  185.  
  186.  
  187. BACKUP DATABASE PacijentDoktorPregled TO
  188. DISK = '(local)'
  189.  
  190. drop table Pregled
  191. select * from Pregled
  192. use PacijentDoktorPregled
  193.  
  194. USE master
  195. RESTORE DATABASE PacijentDoktorPregled FROM
  196. DISK ='(local)'
  197. WITH REPLACE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement