Lab Sheet 08 (ICT.005)
Lab Sheet 08 (ICT.005)
Practical Recording.
Page 1 of 10
SEU/IS/18/ICT/005
Page 2 of 10
SEU/IS/18/ICT/005
Project:
mysql> ALTER TABLE project
-> ADD PRIMARY KEY (Pno);
Works_on:
mysql> ALTER TABLE works_on
-> ADD PRIMARY KEY (Eid);
Location:
mysql> ALTER TABLE Location
-> ADD PRIMARY KEY (Dno);
Department:
mysql> ALTER TABLE Department
-> ADD PRIMARY KEY(Dno);
Page 3 of 10
SEU/IS/18/ICT/005
3. Set Dname of the table DEPARTMENT and Pname of the table PROJECT to UNIQUE.
mysql> ALTER TABLE department
-> ADD CONSTRAINT UNIQUE (Dname);
Page 4 of 10
SEU/IS/18/ICT/005
8. Drop the default value ‘12.0’ and set it back to ‘13’ for Hours in WORKS_ON table.
mysql> ALTER TABLE works_on
-> ALTER hours SET DEFAULT 13;
9. Add the foreign keys to the tables created above using the details given in the following
table.
fk_Dno:
mysql> ALTER TABLE EMPLOYEE
-> ADD CONSTRAINT fk_Dno
-> FOREIGN KEY (Dno) REFERENCES deparment (Dno);
Page 5 of 10
SEU/IS/18/ICT/005
fk_Mgr:
mysql> alter table department
-> add constraint fk_mgr
-> foreign key (mid) references employee(nic);
fk_Dnumber:
mysql> ALTER TABLE location
-> ADD CONSTRAINT fk_Dnumber
-> FOREIGN KEY(Dno) REFERENCES department(Dno);
fk_Dnum:
mysql> ALTER TABLE project
-> ADD CONSTRAINT fk_Dnum
-> FOREIGN KEY(Dno) REFERENCES department(Dno);
fk_loc:
mysql> ALTER TABLE project
-> ADD CONSTRAINT fk_loc
-> FOREIGN KEY(Plocation) REFERENCES department(Dno);
fk_emp:
mysql> ALTER TABLE works_on
-> ADD CONSTRAINT fk_emp
-> FOREIGN KEY(emp_nic) REFERENCES department(nic);
fk_Dnum:
mysql> ALTER TABLE works_on
-> ADD CONSTRAINT fk_Dnum
Page 6 of 10
SEU/IS/18/ICT/005
Exercise 02:
1. Display the entire details of all the employees.
SELECT * FROM employee;
Page 7 of 10
SEU/IS/18/ICT/005
2. Display the NIC of the managers (Hint: Mgr_NIC from table DEPARTMENT).
3. Display the available projects with their project number (Hint: Pname, Pnumber from
table PROJECT).
Page 8 of 10
SEU/IS/18/ICT/005
5. Find out the NIC of employees who works either in Project 1 or in Project 5.
mysql>SELECT emp_NIC
->FROM works_on
->WHERE pno In(1,5);
6. Display the names (Fname and Lname), NIC and Salary of the employees who obtain a
salary more than 40000.
Page 9 of 10
SEU/IS/18/ICT/005
7. Display the NIC of the employees who work less than 15 hours.
mysql>SELECT Emp_NIC
->FROM WORKS_ON
->WHERE Hours <15;
8. In the table LOCATIONS, find out the DISTINCT location of the departments.
mysql>SELECT Dlocation
->FROM location;
9. List the names (Fname and Lname) of the employees who do not work in Department 5.
mysql>SELECT Fname,Lname
->FROM employee
WHERE Dno=5;
Discussion:
Studied about how to modify constraint created tables.
Learned about how to use SELECT statement appropriately.
Page 10 of 10