Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create database PacijentDoktorPregled
- use PacijentDoktorPregled
- go
- create table Pacijenti
- (
- PacijentID INT NOT NULL IDENTITY(1,1) CONSTRAINT PK_PacijentID PRIMARY KEY,
- JMBG nvarchar(13) not null constraint uq_jmbg unique,
- Prezime nvarchar(50) not null,
- Ime nvarchar(50) not null,
- DatumRodjenja date DEFAULT null,
- DatumKreiranja date not null DEFAULT GETDATE(),
- DatumModifikovanja date DEFAULT null
- )
- create table OsobljeTitule
- (
- TitulaID int not null identity(1,1) constraint PK_TitulaID PRIMARY KEY,
- Naziv nvarchar(100) not null,
- DatumKreiranja date DEFAULT GETDATE(),
- DatumModifikovanja date DEFAULT null,
- )
- create table Osoblje
- (
- OsobljeID INT NOT NULL IDENTITY(1,1) CONSTRAINT PK_OsobljeID PRIMARY KEY,
- TitulaID INT NOT NULL CONSTRAINT FK_TitulaID FOREIGN KEY REFERENCES OsobljeTitule(TitulaID),
- Prezime nvarchar(50) not null,
- Ime nvarchar(50) not null,
- DatumKreiranja date DEFAULT GETDATE(),
- DatumModifikovanja date DEFAULT null
- )
- create table Pregled
- (
- PacijentID INT NOT NULL CONSTRAINT FK_PacijentID FOREIGN KEY REFERENCES Pacijenti(PacijentID),
- OsobljeID INT NOT NULL CONSTRAINT FK_OsobljeID FOREIGN KEY REFERENCES Osoblje(OsobljeID)
- CONSTRAINT PK_PacijentID_OsobljeID PRIMARY KEY(PacijentID,OsobljeID),
- PregledID INT NOT NULL,
- DatumPregleda date DEFAULT GETDATE(),
- Dijagnoza nvarchar(100) not null
- )
- ALTER TABLE Pregled
- ADD DatumKreiranja date DEFAULT GETDATE(),
- DatumModifikovanja date DEFAULT NULL
- GO
- insert into Pacijenti(JMBG,Prezime,Ime,DatumRodjenja,DatumModifikovanja)
- Select LEFT( convert(nvarchar(255),NEWID()),13) AS JMBG,LastName,FirstName,BirthDate,Getdate()
- from Northwind.dbo.Employees
- select*
- from Pacijenti
- drop database PacijentDoktorPregled
- INSERT INTO OsobljeTitule (Naziv)
- VALUES ('Stomatolog'),
- ('Oftalmolog'),
- ('Ginekolog'),
- ('Pulmolog'),
- ('Onkolog')
- select*
- from OsobljeTitule
- insert into Osoblje(TitulaID,Prezime,Ime)
- select TOP 2 3, au_lname,au_fname
- from pubs.dbo.authors
- ORDER BY NEWID()
- select*
- from Osoblje
- go
- select * from Pregled
- create procedure usp_insert_pregled
- @PacijentID INT,
- @OsobljeID INT,
- @PregledID INT,
- @DatumPregleda date,
- @Dijagnoza nvarchar(100),
- @DatumKreiranja date,
- @DatumModifikovanja date
- as
- begin
- insert into Pregled
- values(@PacijentID,@OsobljeID,@PregledID,@DatumPregleda,@Dijagnoza,@DatumKreiranja,@DatumModifikovanja)
- end
- DECLARE @date date
- SET @date = Cast(getdate() as date)
- exec usp_insert_pregled 1,1,4,@date,'nesto',@date,null
- exec usp_insert_pregled 19,1,2,@date,'nesto',@date,null
- SELECT*
- FROM Pregled
- select * from Pacijenti
- ALTER TABLE Pacijenti
- add email nvarchar(100) default null,
- lozinka nvarchar(100) default null
- create procedure p_pacijenti(
- @email nvarchar(100),
- @lozinka nvarchar(100)
- )
- as
- begin
- update Pacijenti
- set email=Ime+Prezime+@email,
- lozinka=@lozinka
- where DatumModifikovanja is not null
- end
- declare @email nvarchar(20)='@edu.fit.ba'
- declare @lozinka nvarchar(20)=left(newid(),12)
- exec p_pacijenti @email,@lozinka
- drop procedure p_pacijenti
- select * from Pacijenti
- select * from Pacijenti
- select * from Pacijenti
- select p.Ime,p.Prezime,pp.Dijagnoza,o.Ime+o.Prezime+ot.Naziv as 'Doktor'
- from Pacijenti as p join Pregled as pp on p.PacijentID=pp.PacijentID
- join Osoblje as o on pp.OsobljeID=o.OsobljeID join OsobljeTitule as ot
- on ot.TitulaID=o.TitulaID
- where p.email like 'L%' or pp.Dijagnoza is not null
- create nonclustered index ix_Pacijenti
- on Pacijenti(Ime,Prezime)
- include(email)---provjeri ovo ja msm da je uredu nisam siguran...
- create procedure p_delete(
- @PacijentID int
- )
- as begin
- delete from Pacijenti where PacijentID=@PacijentID and
- PacijentID not in (select PacijentID from Pregled)
- end
- drop procedure p_delete
- exec p_delete 31
- select * from Pacijenti
- select * from Pregled
- BACKUP DATABASE PacijentDoktorPregled TO
- DISK = '(local)'
- drop table Pregled
- select * from Pregled
- use PacijentDoktorPregled
- USE master
- RESTORE DATABASE PacijentDoktorPregled FROM
- DISK ='(local)'
- WITH REPLACE
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement