0% found this document useful (0 votes)
35 views

Create User Smith With Privilege That Allow Him To Create Tables and Connections

The document describes creating database tables for a university system. It includes: 1. Creating a user account for "smith" with privileges to create tables and connections. 2. Using DDL statements to create 7 tables - Professor, Project, Work_In, Departments, Work_Dept, Graduate, Work_Proj - with attributes and foreign key constraints. 3. Sample INSERT statements to populate the tables with data. 4. Several SQL queries to retrieve information from the tables based on conditions. 5. An ER diagram is proposed for the tables with entities, relationships, keys and attributes identified.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Create User Smith With Privilege That Allow Him To Create Tables and Connections

The document describes creating database tables for a university system. It includes: 1. Creating a user account for "smith" with privileges to create tables and connections. 2. Using DDL statements to create 7 tables - Professor, Project, Work_In, Departments, Work_Dept, Graduate, Work_Proj - with attributes and foreign key constraints. 3. Sample INSERT statements to populate the tables with data. 4. Several SQL queries to retrieve information from the tables based on conditions. 5. An ER diagram is proposed for the tables with entities, relationships, keys and attributes identified.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

‫نسرين أحمد سلمان‬

220191910
* Create user smith with privilege that allow him to create tables and connections.

CREATE USER 'smith’ IDENTIFIED BY 'nis123123';

GRANT CREATE table, create session ON db. TO 'smith ‘;

* DDL statements to create the tables


1. CREATE TABLE PROFESSOR (
SSN int (10) primary key,
name char (20),
age   int (10),
R_specialty   *char (40),
rank char (15));

2. CREATE TABLE PROJECT (


Pnumber   int (10) Primary key,
name char (10),
starting date,  
ending_data date,
budget int (10),
ssn_pro int (10)
);

3. CREATE TABLE WORK_IN (


ssn int (10),
Pnumber int (10),
foreign key(ssn) references PROFESSOR (ssn),
foreign key (Pnumber) references PROJECT(Pnumber)

);

4. CREATE TABLE departments (


dnumber int (10) primary key,
name char (40),
Office char (20),
Ssn_pro int,
foreign key (Ssn_pro) references PROJECT(Ssn_pro)
);
5. CREATE TABLE WORK_dept (
ssn int (10),
dnumber int (10),
time char (50),
foreign key(ssn) references PROFESSOR (ssn),
foreign key(dnumber) references departments(dnumber)
);

6. CREATE TABLE GRADUATE (


SSN int (10) primary key,
name char (20),
avg_degree int (10),
age   int (10),
dnumber int (10),
advise int (10),
foreign key(dnumber) references departments(dnumber)
);

7. CREATE TABLE WORK_PROJ (


Snn int (10),
Gradute_no int (10),
pnumber int (10),
foreign key (Pnumber) references PROJECT(Pnumber),
foreign key (Gradute_no) references GRADUATE(SSN)
);
* Write Queries for the following:
insert the sample data shown above into the tables

-INSERT INTO PROFESSOR (SSN, name, age, R_specialty, rank)


VALUES (1, 'Ahmed', 35, 'science','assistant');
- INSERT INTO PROJECT (Pnumber, name, starting, ending_data, budget, ssn_pro)
VALUES (1, 'program', '1/12/2020', '5/12/2020',400,1);
- INSERT INTO WORK_IN (ssn, Pnumber)
VALUES (1,1); ‫تلقائي رح يتم اضافة البيانات بسبب وجود العالقات ي مس‬
- INSERT INTO departments (dnumber, name, Office, Ssn_pro)
VALUES (1,'khaled','sama',1);
- INSERT INTO WORK_dept (Ssn, Dnumeb, time)
VALUES (1,1,'3:00pm');
- INSERT INTO GRADUTE (SSN, name, avg_degree, age, dnumber, advise)
VALUES (1,'ahmed',99,25,1,1);
- INSERT INTO WORK_PROJ (Snn, Gradute_no, pnumber)
VALUES (1,1,1);

Question h: List all professors whose name begins with 'A' or ‘L’ and age large than 30.
Answer:
SELECT name FROM professor WHERE first_name LIKE 'A%’ OR 'L%’ AND age > 30;
Question i: List full details of departments that don't have any graduate students.
Answer:
SELECT CannotGraduate AS SELECT DISTINCT name FROM StudentsAndNotTaken;
Question j: Find the name and the age of the youngest professors
Answer:
SELECT name AND age FROM professor WHERE age <=50;
Question k: Count the number of different professors’ names.
Answer:
select count (*) as count, name from GRADUTE INNER JOIN professor on Ssn = name group by
name;
Question l: Find the names of student who have work in all projects.
Answer:
SELECT * FROM GRADUTE INNER JOIN Ssn WHERE WORK_dept= ALL (SELECT name FROM
student WHERE project = ‘web’);
Question m: Find the name and the age of the youngest graduate student (use subquery).
Answer:
SELECT * FROM GRADUTE INNER JOIN Ssn WHERE name IN (SELECT name AND age FROM
GRADUTE WHERE age < =18);
Question n: Find the names of professors supervising graduate students that age >22.
Answer:
SELECT name FROM PROFESSOR INNER JOIN GRADUTE ON WHERE age >22;
Question t: Change the name of professor ‘Alex’ to Ali.
Answer:
UPDATE PROFESSOR SET name= REPLACE (name, 'Alex', ‘Ali’) WHERE number like ‘Alex%'
Question u: Delete the record for the student whose name is ‘Ali’ and age 22.
Answer:
Answer: DELETE FROM GRADUTE WHERE age = 22 AND name =’Ali’;

Identify the entities, relationships, key attributes and other


attributes and then design the ER diagram:
‫انه للجدول العلوي‬
ERD for given description
Entities - Project, Professor, Graduate student, Department and Advisor
All primary keys ‫ألنه هنالك خط اسفلهم‬.

weak entities – ‫ال يحتوي على مفتاح أساسي‬


Relationships
one-to-many:

.‫ يدير كل مشروع أستاذ واحد ولكن يمكن لألساتذة إدارة مشاريع متعددة‬:‫المشروع واألستاذ‬

.‫ لكل طالب مرشد واحد ولكن يمكن للمرشد أن ينصح العديد من الطالب‬:‫المستشار وطالب دراسات عليا‬
many- to -many:

‫ ويمكن لألساتذة العمل في مشاريع متعددة‬.‫ يعمل على كل مشروع أستاذ واحد أو أكثر‬:‫المشروع واألستاذ‬.

‫ ويمكن أن يعمل على‬.‫ يعمل على كل مشروع واحد أو أكثر من طالب الدراسات العليا‬:‫الطالب والمشروع والخريج‬
‫المشروع العديد من الطالب‬.

.‫ يعمل األساتذة في قسم واحد أو أكثر ويمكن أن يكون هناك العديد من األساتذة‬:‫األستاذ والقسم‬

‫ يمكن لكل أستاذ اإلشراف على عدة طالب ويمكن أن يشرف العديد من األساتذة على‬:‫طالب الدراسات العليا وأستاذ‬

.‫الطالب في مشاريعهم‬
* Identify the entities, relationships, key attributes and other
attributes and then design the ER diagram:
Entities are:
Hotel – Rooms – Cost – Facilities -Location
Relationship:
Hotel 1 – M Rooms
Rooms 1- 1 Cost
Hotel 1 – M Facilities
Hotel 1- 1 Location
Key attribute:
Hotel-hotelId / Rooms-Room-Num / Cost: CostId / Facilities-FacId / Location: Loccode
Other attributes:
Hotel: Name-Rate / Rooms: type /Cost: cost / Facilities-Fname / Location: address-city
ER DIAGRAM:
‫تم تصميم الدايجرام هنا على الورد تأكد بنفسك بفصل العناصر‬

hotelId

type
Name Hotel 1
M
Rate Rooms Room-Num

1
1
1

M Facilitie 1
1 s
Cost CostId
Location FacId
Fnamea
city cost
Loccode
address

You might also like