Final Assignment (2) Muhammad Uzair Class No (260) Section (E) Reg No (39626) Database Administration
Final Assignment (2) Muhammad Uzair Class No (260) Section (E) Reg No (39626) Database Administration
Class No : 260
Section : (E)
Department : IBMS
Discipline : (BSCS)
THE UNIVERSITY OF AGRICULTURE
PESHAWAR PAKISTAN
Question 5
Display total number of records in attribute(Emp_Name) from EMPLOYEE table.
SELECT COUNT(Emp_Name) FROM employee;
Question 6
Display “Name” column from EMPLOYEE table in upper case.
SELECT UPPER(Name) AS Uppercase Name FROM employee;
Question 7
Select distinct DEPARTMENT from EMPLOYEE table.
SELECT distinct(DEPARTMENT) FROM employee;
Question 8
Print the FIRST_NAME from Worker table after replacing ‘a’ with ‘all’.
SELECT Name,REPLACE(Name,’a’,’all’) FIRST_NAME FROM worker;
Question 9
Add CHECK constraint on Gender column using ALTER command.
ALTER table student add constraint chk check(gender in ‘male’,’female’));
Question 10
Select the Departments that have total employee number is 5.
SELECT department COUNT(*) as ‘number of employee’=5;
Question 11
Write an SQL query to show all departments along with the number of people in there.
COUNT([ALL | DISTINCT] department);
Question 12
Display the name of Students in descending order from STUDENT table.
SELECT Name FROM student order by name DESC;
Question 13
Using create command copy STUDENT Table into NEW_Student Table
CREATE table NEW_student as(SELECT*FROM student);
Question 14
Using Alter command add two columns Age and Course to table Student.
ALTER table student add age int,course varchar(20);
Question 15
Using Alter command DROP column Course from table STUDENT
ALTER table student drop column course;
Question 16
Using ALTER command add a primary key for Student_id in STUDENT table.
ALTER table student add student_id primary key;
Question 17
Display list of Employees form EMPLOYEE table whose SALARY is 100000, 5000, and
4000.
SELECT* FROM employee where salary in(100000,5000,4000);
Question 18
Write a full join query for EMPLOYEE and DEPARTMENT table (d.id=emp.did)
SELECT* FROM employee full outer join department on employee emp.id=department d.id
Question 19
Write a query that select all data from EMPLOYEE and DEPARTMENT tables
simultaneously.
SELECT* FROM employee, department;
Question 20
RENAME A TABLE STUDENT TO NEW_STUDENT.
RENAME TABLE STUDENT, NEW_STUDENT