0% found this document useful (0 votes)
12 views14 pages

1 Amanuel Atto 1305462 2 Getahun Zewud 1306029 3 Liuneh Belay 1301921 4 Yohannes G/Selasse 1303090 5 Natnael Akalu 1302352 6 Beamlak Cherinet

The document describes a database project that includes creating tables, inserting data, creating stored procedures, creating roles and granting permissions. It creates tables for patients, treatments, books, borrowing and authors. It then creates logins, maps them to users, creates schemas, views and roles while granting various permissions.

Uploaded by

eliasferhan1992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views14 pages

1 Amanuel Atto 1305462 2 Getahun Zewud 1306029 3 Liuneh Belay 1301921 4 Yohannes G/Selasse 1303090 5 Natnael Akalu 1302352 6 Beamlak Cherinet

The document describes a database project that includes creating tables, inserting data, creating stored procedures, creating roles and granting permissions. It creates tables for patients, treatments, books, borrowing and authors. It then creates logins, maps them to users, creates schemas, views and roles while granting various permissions.

Uploaded by

eliasferhan1992
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

INSTITUTE OF TECHNOLOGY SCHOOL OF COMPUTING OF

INFORMATION TECHNOLOGY
ADDVANCED DATABASE GROUP PROJECT

GROUP MEMBERS

NO NAME ID

1 AMANUEL ATTO 1305462


2 GETAHUN ZEWUD 1306029
3 LIUNEH BELAY 1301921
4 YOHANNES G/SELASSE 1303090
5 NATNAEL AKALU 1302352
6 BEAMLAK CHERINET
CREATE DATABASE relationSs

;
USE relationSs;

-- Create the Patient table


CREATE TABLE PatientS ( PID VARCHAR(20)
PRIMARY KEY,
PFname VARCHAR(50),
Sex CHAR(1),
Age INT,
Address VARCHAR(50),
PhoneNumber VARCHAR(20)
);
-- Insert data into the Patient table
INSERT INTO Patient VALUES ('p12',
'Abebe', 'M', 23, 'Bahir Dar',
'0112334555');
INSERT INTO Patient VALUES ('p13',
'Aster', 'F', 20, 'Gondar', '0112334455');

-- Create the Treatment table


CREATE TABLE Treatmentss (PID VARCHAR(20),
PHYid VARCHAR(50),
Diagnosis VARCHAR(30),
FOREIGN KEY (PID) REFERENCES PatientS
(PID)
);

-- Insert data into the Treatment table


INSERT INTO Treatment VALUES ('p13',
'phy23', 'Malaria');
INSERT INTO Treatment VALUES ('p12', 'phy21', 'TB');

-- Create the stored procedure


CREATE PROCEDURE
GetPatientSWithTreatmentss as
SELECT p.PID, p.PFname
FROM PatientS p
JOIN Treatmentss t ON p.PID = t.PID
WHERE UPPER(t.Diagnosis) = 'MALARIA'
AND UPPER(p.Address) = UPPER(Address) AND
p.Sex = Sex;

-- Select data from tables to review


SELECT * FROM Patientss;
SELECT * FROM TreatmentS;
EXEC GetPatientSWithTreatmentss;
2,
2.1
CREATE LOGIN Bezawt WITH PASSWORD =
'SecurePassword';
CREATE LOGIN Tolosa WITH PASSWORD =
'SecurePassword';
CREATE LOGIN Kedr WITH PASSWORD =
'SecurePassword';
-- Map logins to database users
CREATE USER Bezawt FOR LOGIN Bezawit;
CREATE USER Tolosa FOR LOGIN Tolosa;
CREATE USER Kedr FOR LOGIN KedSr;

2.2

CREATE SCHEMA Library_Member AUTHORIZATION


Bezawit;
CREATE TABLE Library_Member.Student (fname
VARCHAR(50),
studID INT,
sex CHAR(1),
department VARCHAR(50)
);

INSERT INTO Library_Member.Student VALUES


('Amanuel', 1305462, 'M', 'IT');
INSERT INTO Library_Member.Student VALUES
('Natinael', 1305464, 'M', 'IT');
Select * from Library_Member.Student;

CREATE TABLE Library_Members.Instructor ( fname


VARCHAR(50),
InstID INT,
sex CHAR(1),
salary DECIMAL(10, 2)
);

INSERT INTO Library_Members.Instructor VALUES


('Ayele', 123, 'M', 2000.00);
INSERT INTO Library_Members.Instructor VALUES
('Tigst', 12, 'M', 1300.50);
Select * from Library_Members.Instructor;

2.3-- Create the Library_Resources schema and


AdvancedBooks view
CREATE SCHEMA Library_Resource AUTHORIZATION
Kedrss;
CREATE TABLE Library_Resource.books (bookid
VARCHAR(50) primary key,
title varchar(100),
year int );

INSERT INTO Library_Resource. books VALUES


('itec2013', 'Advanced Database', 1998);
INSERT INTO Library_Resource.books VALUES
('itec2034', 'java programing', 2001);
INSERT INTO Library_Resource.books VALUES
('itec2014', 'Advanced Database', 2002);
INSERT INTO Library_Resource.books VALUES
('itec2035', 'internet programing', 2005);

Select * from Library_Resource. Books;


CREATE TABLE Library_Resources.book_borrowing
(instid VARCHAR(50) ,
ISBN VARCHAR(100), date int primary key
(instid, ISBN));

INSERT INTO Library_Resources.book_borrowing


VALUES ('W123', '1AMAN', 1988);
INSERT INTO Library_Resources.book_borrowing
VALUES ('W133', '1ANAN', 1999);
Select * from
Library_Resources.book_borrowing;
Create schema Author;

Create table Author1(AuthorID int primary key,


Authorename varchar(20), Auterage varchar(20)
);

INSERT into Author1 values(13054, 'amanuel


atto' '26');
INSERT into Author1 values(13043, 'amnan',
'30');
Select * from Author1;
CREATE VIEW Library_Resource. booksS AS
SELECT * FROM books WHERE title = 'Advanced
Database';

2.4-- Create roles: Student, Librarian,


Instructor
CREATE ROLE Student;
CREATE ROLE Librarian;
CREATE ROLE Instructor;
2.5-- Grant permissions to the Librarian role

GRANT SELECT, INSERT, DELETE ON


Library_Resource.Books TO Librarians;

GRANT UPDATE(Date) ON
Library_Resource.Book_borrowings TO Librarians;

GRANT CONTROL ON SCHEMA:: Author1 TO


Librarians;

2.6-- Grant permission to Kedir to see all


records in the Author table
GRANT SELECT ON Author TO Kedir WITH GRANT
OPTION;

2.7-- Revoke all permissions from the Kedir


user on the Author table
REVOKE SELECT FROM Kedrss;

You might also like