Professional Documents
Culture Documents
Yarmouk University
Hijjawi Faculty for Engineering Technology
Industrial Engineering Department
Final Note IS
2.25
0797658644 محمد بواعنه
- 1 -IS
0797658644 محمد بواعنه
- 2 -IS
معالجة البيانات:
اضافة البيانات()INSERT -
حذف البيانات()DELETE -
تعديل البيانات()UPDATE -
اضافة البيانات:
الصيغه العامه:
مالحظه -1 :دائما بال INSERTضع القيم بين ' ' تفاديا الخطأ
-2عند تعريف ال attributeمن نوع charيجب وضع البيانات بين ’‘ .
حذف البيانات(:)DELETE
يتم حذف صف بالكامل حسب الشرط واذا لم يكن شرط يتم حذف كافة الصفوف في الجدول .
الصيغه العامه:
DELETE
FROM TABLE_NAME
WHERE condition1 AND condition2 AND condition N
مثال :لو بدي احذف الموظف الي اسمه االول Joyceو ويعمل في القسم :5
0797658644 محمد بواعنه
- 4 -IS
عشانPRIMARY KEY دائما بالحذف او التعديل اختار الشرط يكون على عامود ال: مالحظه -
.تضمن انك مش رح تحذف اكثر من صف
UPDATE TABLE_NAME
SET Attribute1, Attribute2, Attribute N
WHERE condition 1 AND condition 2 AND condition N
. ال يتم التعديل وما بعطي خطأ123456789 طيب فرضا ما عندنا وال موظف الرقم الوطني اله
Q: Write SQL update statements to do the following on the database schema shown in Figure.
d. Delete the record for the student whose name is ‘Smith’ and whose student number is 17.
0797658644 محمد بواعنه
- 6 -IS
اول صف فيه رقم البوست 1ونص البوست helloوالوقت 11والتاريخ 2018/8/23شو يلي بصير
بجيبوهم خليه خليه حسب رقم البوست وبكون عندهم ستركش عام لالشي هيك مثال
username
Time-date
text
وبنفذو االستعالم وبيتعبى هاذ الستركشر بعدد الصفوف الي موجوده بالجدول
Mohammad bawaneh
11:00AM-23/8/2018
Hello
Mohammad bawaneh
9:20PM-24/8/2018
0797658644 محمد بواعنه
- 7 -IS
Hi
الحياه بسيطه ^_^ .........
بهاذ الجزء رح نتعلم كيف نرجع البيانات هاي بتيبل وكيف نكتب الشروط ونستعلم عن االشي الي بدنا نعرضه بس
,,,
الصيغه العامه :
EX1: Retrieve the birth date and address of the employee(s) whose name is ‘John B.
Smith’.
SOL:
John B. Smith’ رجع تاريخ الميالد و الموقع للموظفين للموظف الي اسمه
اسم الجدول الموظفينFROM , ADDRESS و الموقعBIRTH DATE تاريخ الميالدSELECT ال
John B. Smith الشرط اسم الموظفWHERE الEMPLOYEE
SELECT Bdate, Emp_Address
FROM EMPLOYEE
الناتج بدون الشرط
الناتج مع الشرط
SELECT Dependent_name
FROM EMP_DEPENDENT
0797658644 محمد بواعنه
- 10 -IS
WHERE ESSN='123456789'
EX4: Retrieve the names of employee named = ‘john’ or there salary is more than
40000.00
SOL:
3000.00 او راتبه اكبر منJOHN رجع اسماء الموظفين الي اسمهم
SELECT Fname, Minit,Lname
FROM EMPLOYEE
WHERE Fname='JOHN' OR Salary >40000
0797658644 محمد بواعنه
- 11 -IS
’EX5: Retrieve the name and address of all employees who work for the ‘Research
department.
SOL:
هون عندنا جدولين ف رح احتاج الربط بينهم وبما انو عندنا جدولين الزم جمل الربط JOINيكونو على االقل جمله واحده
,في ال SCHEMAعندنا عالقتين مابين
MGR_SSN SSNو DNO DNUMBERوبما انو العالقه عمل وما جاب سيرة المدراء ف بوخذ
DNO DNUMBER
WHERE Dname=‘Research’
N-1 على االقلJOIN جمل الربطN TABLE اذا كان عندي: مالحظه
3 TABLE JOIN>=3-1=2
EX5: For every project located in ‘Stafford’, list the project number, the controlling
department number, and the department manager’s last name, address, and birth date.
SOL:
0797658644 محمد بواعنه
- 13 -IS
بدو رقم المشروع و القسم المسؤول عن المشروع واالسم االخير, Stafford في اي مشروع موجود في
.للموظف المسؤول عن القسم والموقع وتاريخ الميالد للموظف
3 table هون رح نحتاج
Plocation,pnumber project
Dnumberdepartment or project
Lname,address,bdateemployee
جداول فبدنا جملتين ربط3 استخدمنا
Mangers: ssn=mgr_ssn,controlling dep number : dnumber=dnum
: رح يكون االستعالم
distinct مع
EX:
Let table the information of employee, what output of the following :
* 1- Select
0797658644 محمد بواعنه
- 15 -IS
From employee
Where ssn like '12%'
2- select fname
from employee
where ssn like '__3%'
3- select bdate
from employee,DEPARTMENT
where dno=dnumber and dno>2 and fname like 'j__%'
sol:
1-
2-
3-
: BETWEEN
:الصيغه العامه
INT1 AND 10
شو بصير بكون الناتج حسب الترتيب لل احرفCHAR معBETWEEN طيب لما استخدم -
TEXT{Z,B,C,D,X,I,C,A}
TEXT BETWEEN ‘C’ AND ‘I’
{C,D,I,C} : الناتج بكون
EX:
Return names and employee’s salary for these whose work from 10 to 15 hour
,assume that project LOCATION is HOUSTON and give them a percentage above
the salary 20%.
SOL:
واعطيهمHouston ساعه و موقع المشروع15 الى10 رجع اسماء والرواتب للموظفين الي بشتغلو من
. %20 نسبه فوق الراتب
TABLE1
A B
TABLE2
C A
ونفذنا هذه ال : QUERY
* SELECT
FROM TABLE1,TABLE2
WHERE A=A
هون ال SQLمش رح تعرف انو ال Attribute Aهو ل TABLE1او TABLE2طيب شو الحل ؟ الحل رح
نستخدم ال Aliasingتوضع بعد جملة ال . FROM
SELECT * SELECT *
FROM TABLE1 as T1,TABLE2 as T2 FROM TABLE1 T1,TABLE2 T2
WHERE T1.A=T2.A WHERE T1.A=T2.A
EX:
ساعه و اسم البروجكت25 الى5 رجع اسماء والرواتب للموظفين الي بشتغلو من
EX: For each employee, retrieve the employee’s first and last name and
the first and last name of his or her immediate supervisor.
SOL:
. رجع االسم االول واالخير للموظف واالسم االول واالخير للموظف المشرف عليه, لكل موظف
0797658644 محمد بواعنه
- 19 -IS
EX: A={1,5,A,8,D},B={1,A,3,8}
1- A UNION B={1,5,A,8,D,3}
2- A Intersection B={1,A,8}
3- A EXCEPT B={5,D}
B
NAME ID INFORMATION
0797658644 محمد بواعنه
- 20 -IS
NAME,SSN CHAR(10)
INFROMATIONCHAR(100)
GRADEFLOAT
IDINT
DATA
EX1:
SELECT *
FROM A
UNION
SELECT *
FROM B
بعطي خطأ النو
IDINT والSSN CHAR
INFORMATION CHAR والGRADEFLOAT
EX2:
SELECT NAME,GRADE
FROM A
0797658644 محمد بواعنه
- 21 -IS
UNION
SELECT NAME,ID
FROM B
EX3:
A-
SELECT NAME
FROM A
EXCEPT
SELECT NAME
FROM B
شاشه فارغه
SELECT NAME
FROM B
EXCEPT
SELECT NAME
FROM A
EX4:
0797658644 محمد بواعنه
- 22 -IS
SOL:
EX: Retrieve a list of employees and the projects they are working on, ordered by
department and, within each department, ordered alphabetically by last name, then first
name.
SOL:
عاديAliasing بدون
QUESTION:
Q: Make a list of projects number for employees whose last name is ‘smith’ who works on
project or manager on the department responsible for the project.
SOL:
الذي يعمل بمشروع او مدير على القسم المسؤولsmith كون قائمه ب ارقام المشاريع للموظفين التي االسم االخير لهم
. عن المشروع
SELECT DISTINCT Pnumber
FROM PROJECT, DEPARTMENT, EMPLOYEE
WHERE Dnum=Dnumber AND Mgr_ssn=Ssn
AND Lname='Smith'
UNION
( SELECT DISTINCT Pnumber
FROM PROJECT, WORKS_ON, EMPLOYEE
WHERE Pnumber=Pno AND Essn=Ssn
AND Lname='Smith' );
pnumber=pno وجملةproject ؟ ال لو شلنا ال جدولproject هل بالضروره اوخذ جدول الUNION بعد ال
OR
Q:
Return the name of the employee responsible for projects whose working hours greater than
15 hours.
SOL:
. ساعه15 رجع اسم الموظفين المسؤولين عن المشاريع التي تتجاوز ساعات العمل فيها عن
Q: Retrieve the names of all employees in department 5 who work more than 10 hours on
the Project X
SOL:
PROJECT X الذين يعملون اكثر من عشر ساعات على5 رجع اسماء الموظفين في القسم
Q: List the names of all employees who have a dependent with the same first name as
themselves.
SOL:
SELECT Fname,Lname
FROM EMP_DEPENDENT,EMPLOYEE
WHERE SSN=Essn AND Dependent_name=Fname
Q: Find the names of all employees who are directly supervised by ‘Franklin Wong’.
SOL:
SELECT B.FNAME,B.LNAME
FROM EMPLOYEE A,EMPLOYEE B
WHERE A.SSN=B.Super_ssn AND A.Fname='Franklin' AND A.Lname='Wong'
OR
SELECT A.FNAME,A.LNAME
FROM EMPLOYEE A,EMPLOYEE B
WHERE B.SSN=A.Super_ssn AND B.Fname='Franklin' AND B.Lname='Wong'
0797658644 محمد بواعنه
- 27 -IS
Q: Find the names of all employees and project number who are directly supervised by
‘Franklin Wong’
SOL:
Q: For each employee, retrieve the employee’s first last name , dependent name and the
first and last name of his or her immediate supervisor where project name Contain character
‘x’
Sol:
x رجع اسم الموظف واسم العائل واسم السؤول عنه اذا كان اسم البروجكت يحتوي على حرف
SELECT E.Fname,E.Lname,Dependent_name,Pname, S.Fname AS
FnameSUPER,S.Lname AS LnameSUPER
0797658644 محمد بواعنه
- 28 -IS
SOL:
SELECT SSN,FNAME
FROM EMPLOYEE
EXCEPT
SELECT SSN,FNAME
FROM EMPLOYEE,EMP_DEPENDENT
WHERE SSN=ESSN
مهــــــــــــم
Q:Consider the following operation , what constraint do they violate and how ,explain:
a-
insert into EMP_DEPENDENT values('123456789','Alice','F','1999-12-5','son')
Q15:
Write SQL statement update department number=2 where department number =5?
- What constraint have been violated by this operation explain?
FK constraint ما بصير هون بتكون المشكله
-Assume that the update operation on department table will be cascade, what will be the
result of executing the following sql statement after update you have made ,select dnumber
from department_location?
dnumber
1
4
2
2
2
-Assume that the update operation on department table will be SET NULL, what will be the
0797658644 محمد بواعنه
- 30 -IS
result of executing the following sql statement after update you have made ,select dnumber
from department_location:
dnumber
1
4
null
null
null
Q16:
1- retrieve location for department number =5 and manger start date =12/2/2002
select Dlocation
from Department , DEPT_LOCATION
where DEPT_LOCATION .Dnumber = 5 and Mgr_start_date = '12-2-2002' and
DEPT_LOCATION.Dnumber = Department .Dnumber
2- retrieve number of hours and project name where the manger name ='john' and
dep_location ='hoston'
3- For all department mangers retrieve their addresses and the names of the project that
work on 3 hours at least :
--Query 0
--Retrieve the birthdate and address of the employee(s) whose name is
--John B. Smith
--
select bdate,address
from employee
where fname='John' and minit='B' and lname='Smith';
--
--Query 1
--Retrieve the name and address of all employees who work for the Research
--department.
--
select fname,lname,address
from employee,department
where dnumber=dno and
dname='Research';
--
--Query 2
--For every project located in Stafford, list the project number, the
--controlling department number, and the department manager's last name,
--address, and birthdate.
--
select pnumber,dnum,lname,address,bdate
from project,department,employee
where dnum=dnumber and mgrssn=ssn and plocation='Stafford';
--
0797658644 محمد بواعنه
- 32 -IS
--
--Query 3
--Make a list of all project numbers for projects that involve an employee whose
--last name is Smith either as a worker or as a manager of the department that
--controls the project.
--
(select distinct pnumber
from project,department,employee
where dnum=dnumber and mgrssn=ssn and lname='Smith')
union
(select pnumber
from project,works_on,employee
where pnumber=pno and essn=ssn and lname='Smith');
--
--Query 5
--Retrieve the names of all employees who have two or more dependents.
--
--Query 8
--For each employee, retrieve the employee's first and last name and the first
--and last name of his or her immediate supervisor
--
select e.fname,e.lname,s.fname,s.lname
from employee as e, employee as s
where e.superssn = s.ssn;
--
--Query 9
--Retrieve all employee SSNs
--
select ssn
from employee;
--
--Query 10
--Retrieve all combinations of SSN and DEPARTMENT NAME
--
select ssn,dname
from employee,department;
--
--Query 11
--Retrieve the salary of every employee
--
select all salary
from employee;
--
--Query 11a`
--Retrieve the distinct salary values
0797658644 محمد بواعنه
- 33 -IS
--
select distinct salary
from employee;
--
--Query 12
--Retrieve all employees whose address is in Houston, Texas
--
select fname,lname
from employee
where address like '%Houston, TX%';
--
--Query 13
--Show the resulting salaries if every employee working on the ProductX project
--is given a 10% raise.
--
select fname,lname,1.1*salary as increased_sal
from employee,works_on,project
where ssn=essn and pno=pnumber and pname='ProductX';
--
--Query 14
--Retrieve all employees in department 5 whose salary is between $30,000 and
--$40,000
--
select *
from employee
where dno=5 and (salary between 30000 and 40000);
--
--Query 15
--Retrieve a list of employees and the projects they are working on, ordered
--by department and, within each department, ordered alphabetically by last
--name, first name
--
select dname,lname,fname,pname
from department,employee,works_on,project
where dnumber=dno and ssn=essn and pno=pnumber
order by dname,lname,fname;
--
--
--
0797658644 محمد بواعنه
- 34 -IS
: سنوات
Q:classfay the following SQL operation DDL or DML:
Update:DML
Create:DDL
Delete:DML
Sol:
delete from project where Plocation='Stafford' or Plocation='Sugarland'
2. Assume that the delete operation on project table will be cascade, what will be the
result of executing the following sql statement after deletion you have made :
d- Write SQL statement to modify the location of the project number 1 (pnumber=1) to
‘Hosuton’:
SOL:
update project set Plocation='Houston' where Pnumber=1
e- Consider the following operation , what constraint do they violate and how ,explain:
2. Retrieve full name of all employees whose first name starts will letter ‘j’
SOL:
Select fname,minit,lname
From employee
Where fname like ‘j%’
4. For all department mangers retrieve their addresses and the project numbers of the
project that work on :
SOL:
select Emp_Address,Pno
from DEPARTMENT,EMPLOYEE,WORKS_ON
where ssn=mgr_ssn and ssn=essn
5. For all department mangers retrieve their addresses and the names of the project that
work on:
SOL:
select Emp_Address,Pname
from DEPARTMENT,EMPLOYEE,WORKS_ON,project
where ssn=mgr_ssn and ssn=essn and pno=Pnumber
7)sol:B
Q:
Use company database :
a- .
0797658644 محمد بواعنه
- 38 -IS
Sol:
Not correct ,2 not subset department(dnumber)
Referential integrity constraint.
b-.
Sol:
lname hours
wong 10.0
wollace 20.0
wollace 15.0
C:
1- .
Select ssn
From employee,dependent
Where ssn=essn and relationship=’deughters’
2- .
Select dname
From department d,dept_locations dl
Where d.dnumber=dl.dnumber and dlocation=’sugarland’
3- .
Select dependent_name
From employee e,dependent d
Where ssn=essn,d.sex=’F’ and fname=’Franklin’ and minit=’T’ and
lname=’Wong’
4- .
0797658644 محمد بواعنه
- 39 -IS
Select hours
From department,works_on,employee
Where ssn=essn and ssn=mgr_ssn and pno=20 and dname=’administration’
Q:
Sol:
Select Essn
From dependent
Where relationship=’daughters’
b)
Sol:
Select dname
From department d,dep_location dl
Where d.dnumber=dl.dnumber and dlocation=’sugarland’
0797658644 محمد بواعنه
- 40 -IS
c)
Sol:
Select fname
From works_on,employee
Where essn=ssn and pno=20 and sex=’F’
d)
e)
Q:
a)
c)
1- SELECT COUNT(*)
FROM EMPLOYEE
3- SELECT SUM(FNAME)
FROM EMPLOYEE
4- SELECT SUM(salary)
FROM EMPLOYEE
5- SELECT max(salary)
FROM EMPLOYEE
SOL:
1- .
2- .
3- .
نفسavg بتعامل مع ارقام ولو كانsum والchar من نوعfname النو الerror بيعطي
. االشي
4- .
5- .
6- .
7- .
Ex20: return the number of employees and their total salaries for the
employees who work more than 10 hours
Sol:
رجع عدد الموظفين و مجموع رواتبهم للموظفين الذين يعملون اكثر من عشر ساعات
select count(*) , sum(salary)
from employee,WORKS_ON
where ssn=essn and Emp_Hours>10
EX22: Find the sum of the salaries of all employees of the ‘Research’
department, as well as the maximum salary, the minimum salary, and the
average salary in this department.
SOL:
0797658644 محمد بواعنه
- 44 -IS
و اعلى راتب و اقل راتب والوسط الحسابيRESEARCH مجموع الرواتب للموظفين الي في
للرواتب
SELECT ______________
FROM ______________
WHERE ____________
GROUP BY _____________
HAVING ( Condition )
3- SELECT LNAME
FROM EMPLOYEE
GROUP BY DNO
4- .
SELECT DNO
FROM EMPLOYEE
GROUP BY DNO
5- SELECT AVG(SALARY)
FROM EMPLOYEE
GROUP BY DNO
6- SELECT AVG(SALARY)
FROM EMPLOYEE
GROUP BY SALARY
HAVING SALARY >20000
0797658644 محمد بواعنه
- 46 -IS
7- SELECT AVG(DNO)
FROM EMPLOYEE
GROUP BY LNAME
HAVING SALARY >20000
SOL:
1- .
2- .
3-
GROUP BY الزم يكون بSELECT النو الي الزم نكتبه بالERORR بيعطي
4- .
5- .
6- .
0797658644 محمد بواعنه
- 47 -IS
EX26: For each department, retrieve the department number, the number of
employees in the department, and their average salary.
SOL:
SELECT Dno, COUNT (*), AVG (Salary)
FROM EMPLOYEE
GROUP BY Dno
EX27: For each project, retrieve the project number, the project name, and the
number of employees who work on that project.
SOL:
. رجع رقم المشروع واسمه وعدد الموظفين الذين يعملون في هذا المشروع, لكل مشروع
SELECT Pnumber, Pname, COUNT (*) #EMPLOYEE
FROM PROJECT, WORKS_ON
WHERE Pnumber=Pno
GROUP BY Pnumber, Pname
EX28: For each project on which more than two employees work, retrieve the
project number, the project name, and the number of employees FROM
DEPARTMENT 5 who work on the project.
SOL:
رجع رقم واسم المشروع وعدد الموظفين الذين يعملون في,لكل مشروع الذي يعمل فيه اكثر من موظفين
. هذا المشروع
SELECT Pnumber, Pname, COUNT (*)
FROM PROJECT, WORKS_ON
WHERE Pnumber=Pno AND DNO = 5
GROUP BY Pnumber, Pname
HAVING COUNT (*) > 2
0797658644 محمد بواعنه
- 49 -IS
EX29: List the names of managers who have at least two dependent.
SOL:
: قائمه ب اسماء الموظفين المسؤولين الي الهم عائلين على االقل
SELECT Fname, Lname
FROM EMPLOYEE
WHERE SSN IN ( SELECT ESSN
FROM EMP_DEPENDENT)
AND SSN NOT IN ( SELECT MGR_SSN
FROM DEPARTMENT)
GROUP BY FNAME,LNAME
HAVING COUNT(*)>=2
EX30:
List of names employee those who have 3 dependent .
Sol:
. عوائل3 قائمه ب اسماء الموظفين الذين لهم
select fname,Lname
from employee ,EMP_DEPENDENT
where ssn =Essn
group by fname,lname
having count(Fname)=3
0797658644 محمد بواعنه
- 50 -IS
EX31: For each department whose average employee salary is more than
$30,000, retrieve the department name and the number of employees working
for that department.
SOL:
استرجع اسم القسم و عدد الموظفين الذين, 30000 لكل قسم فيه الوسط الحسابي للراتب اكبر من
يعملون في القسم
SELECT DNAME,COUNT(*)
FROM EMPLOYEE , DEPARTMENT
WHERE DNO=Dnumber
GROUP BY DNAME
HAVING AVG(SALARY)>30000
EX33: Retrieve the department name and department manager full name, for
each department whose maximum salary is more than $41,000.
SOL:
select Dname,fname,lname
from EMPLOYEE , DEPARTMENT
where ssn=Mgr_ssn
group by Dname,fname,Lname
having max(Salary)>41000
0797658644 محمد بواعنه
- 51 -IS
EX34: Retrieve the number of female employees for each department whose
maximum salary is more than $41,000.
SOL:
select Dnumber,COUNT(*)
from EMPLOYEE,DEPARTMENT
where dno=Dnumber and sex='f'
group by Dnumber
having max(Salary)>41000
0797658644 محمد بواعنه
- 52 -IS
-حذف : VIEW
DROP VIEW_NAME
مثال بدنا ننشئ VIEWتحتوي االسم االول للموظفين والراتب اذا كان اكبر من 25000
ونسميها : EM_SALARY
CREATE VIEW EM_SALARY
AS
SELECT FNAME,Salary
FROM EMPLOYEE
WHERE Salary>25000
-اذا بدك تشوف وين انشأت بتروح على COMPANYعلى المجلد : VIEW
EX35:
A- CREATE VIEW (em_de) contains the employee name , dependent
name , salary and dno where dno > 2 .
B- USE VIEW TO SHOW EMPLOYEE NAME AND DEPARTMENT
NAME.
SOL:
يحتوي على اسم الموظف واسم العائل والراتب ورقم القسم اذا كان رقمem_de انشئ مشهد اسمه
2 القسم اكبر من
A-
create view em_de
as select fname,Dependent_name,Salary,Dno
from EMP_DEPENDENT,EMPLOYEE
where ssn=essn and dno>2
0797658644 محمد بواعنه
- 54 -IS
B- .
النو فيه اسماء االقسامDEPARTMENT و جدول الEM_DE هون رح نستخدم ال
select FNAME,Dname
from em_de,DEPARTMENT
WHERE Dno=Dnumber
VIEW وال بعطي خطأ فقط في حالة الOUTPUT الزم تسمي الFUNCTION اذا استخدمت
update
مثال بدي اعدل االسم في ال viewمن nullل saif
البيانات في ال view:
0797658644 محمد بواعنه
- 56 -IS
delete
اذا حذفنا من ال viewرح ينحذف من الجدول employeeكمان الحظ المثال االتي :
delete from em_view where id =5
البيانت في : em_view
البيانات في employee
insert
اذا اضفنا بيانات em_viewرح تنضاف على ال employee
)'insert into em_view values ('6','khaled','045','1044
0797658644 محمد بواعنه
- 57 -IS
)delete اوupdate اوinsert الحظ الحاله االتيه (بهاي الحاله ما بيزبط نعمل
create view No_InUpDe
as
select count(*) as #emp,sum(id) as SumId
0797658644 محمد بواعنه
- 58 -IS
from employee
delete from No_InUpDe where #emp=1: افرض اعملنا هيك
. employee النو اصال هاي البيانات مشتقه من الerror بيعطي
B- .
create view view_con_ADDATT
as
select id,ename,salary*110 AS NEW_SALARY
from employee
where id>2
التعديل بيزبط بكل الحاالت اال حالة اعدل, لكن الحذف بتزبطERROR ما بتزبط بعطيINSERT ال
NEW_SALARY على
: update وinsert وdelete فيerror حاالت ال
Function -1
group by -2
DISTINCT -3
. من جدولين او اكثرview انشاء ال-4
B. A view that has the employee name, supervisor name, and employee
salary for each employee who works in the ‘Research’ department.
SOL:
واسم المسؤول وراتب الموظف للموظفين الذين يعملون في, مشهد يحتوي على اسم الموظف
RESEARCH قسم ال
CREATE VIEW D_N_S(EMP_NAME,SUPER_NAME,EMP_SALARY)
AS
SELECT E2.Fname ,E1.Fname,E2.SALARY
FROM EMPLOYEE E1,EMPLOYEE E2,DEPARTMENT
WHERE E1.SSN=E2.Super_ssn AND E1.Dno=Dnumber AND
Dname='Research'
b- SELECT D, C
FROM DEPT_SUMMARY
WHERE TOTAL_S > 100000;
0797658644 محمد بواعنه
- 60 -IS
C- SELECT D, AVERAGE_S
FROM DEPT_SUMMARY
WHERE C > ( SELECT C FROM DEPT_SUMMARY WHERE D=4);
D- .
UPDATE DEPT_SUMMARY
SET D=3
WHERE D=4;
E- .
DELETE FROM DEPT_SUMMARY
WHERE C > 4;
Sol:
a-
b-
c-
d- .
group by وfunction النو مستخدمينerror بيعطي
e- .
d مثل الفرعerror بيعطي
0797658644 محمد بواعنه
- 61 -IS
سنوات
1) Specify the results of the following queries applied to COMPANY
database state shown above:
1) Write SQL code to add a new attribute /column age of type integer to
the DEPENDENT relation.
ALTER TABLE DEPENDENT ADD age int;
0797658644 محمد بواعنه
- 62 -IS
2) Using SQL Specify a view that has the project name, number of
employees, and total hours worked on the project for each project with
more than two employees working on it.
Create view summery(pname,pnumber,#employee,totalhours)
as
SELECT Pname ,Pnumber, COUNT (*) #EMPLOYEE,sum(hours)
FROM PROJECT, WORKS_ON
WHERE Pnumber=Pno
GROUP BY Pnumber, Pname
Consider the following ER diagram given below and answer the following
questions: