You are on page 1of 14

Name=Vinayak Nagar

Reg.No.=21MCA0015
Sub=Database Technologies
Exercise-I:
1) Insert the data given above in both employee, department and
project tables.

create table Employee(First_Name VARCHAR(15),Mid_Name CHAR(2),Last_Name


VARCHAR(15),SSN_Number CHAR(9) NOT NULL primary key,Birthday
DATE,Address VARCHAR(50),Sex CHAR(1),Salary INT(7),Supervisor_SSN
CHAR(9),Department_Number INT(5) NOT NULL);

create table Department(Department_Name Varchar(15),Department_Number


INT(5) NOT NULL primary key,ManagerSSN CHAR(9),ManageStartDate DATE);

create table Project(Project_Name VARCHAR(15),Project_Number INT(5)NOT


NULL primary key,Project_Location VARCHAR(15),Department_Number INT(5)
NOT NULL);
insert into Employee values ('Doug', 'E', 'Gilbert',554433221, '1960-06-09' ,'11 S
59 E, SaltLake City, UT', 'M', 80000, NULL ,3);

insert into Employee values ('Joyce','', 'PAN' ,543216789, '1978-02-07', '35 S 18 E,


SaltLake City, UT','F' ,70000, NULL, 2);

insert into Employee values ('Frankin', 'T', 'Wong',333445555,'1945-12-08','638


Voss,Houston TX','M', 40000, '554433221', 5);

insert into Employee values ('Jennifer', 'S',' Wallace', 987654321, '1930-06-20',


'291 Berry,Bellaire, TX', 'F', 43000, '554433221', 4);

insert into Employee values ('John', 'B', 'Smith', 123456789 ,'1955-01-09', '731
Fondren,Houston, TX', 'M', 30000 ,'333445555', 5);

insert into Employee values ('Ramesh', 'K', 'Narayan', 666884444 ,'1952-09-15',


'975 Fire Oak,Humble, TX', 'M', 38000 ,'333445555', 5);

insert into Employee values ('Joyce', 'A', 'English', 453453453,'1962-07-31','5631


Rice,Houston, TX', 'F', 25000 ,'333445555', 5);
insert into Employee values ('James', 'E', 'Borg', 888665555,'1927-11-27','450
Stone,Houston, TX', 'M', 55000, '543216789', 1);

insert into Employee values ('Alicia', 'J', 'Zelaya', 999887777, '1958-06-19','3321


Castle, Spring, TX', 'F', 25000, '987654321', 4);

insert into Employee values ('Ahmad','V', 'Jabbar', 987987987, '1959-03-


29','59980 Dallas,Houston, TX ','M', 25000 ,'987654321', 4);

insert into Department values ('Manufacture',1, '888665555', '1971-06-19');

insert into Department values ('Administration',2,'543216789', '1999-01-04');

insert into Department values ('Headquarter',3,'554433221', '1955-07-22');

insert into Department values ('Finance',4,'987654321','1985-01-01');

insert into Department values('Research', 5, '333445555','1978-04-22');


insert into Project values('ProjectA', 3388,'Houston', 1);

insert into Project values('ProjectB',1945, 'Salt Lake City', 3);

insert into Project values('ProjectC', 6688 ,'Houston',5);

insert into Project values('ProjectD', 2423 ,'Bellaire', 4);

insert into Project values('ProjectE', 7745, 'Sugarland',5);

insert into Project values('ProjectF', 1566 ,'Salt Lake City', 3);

insert into Project values('ProjectG', 1234, 'New York', 2);

insert into Project values('ProjectH',3467, 'Stafford', 4);

insert into Project values('ProjectI', 4345, 'Chicago', 1);

insert into Project values('ProjectJ', 2212, 'San Francisco', 2);


2)Display all the employees’ information.
select * from employee;

3)Display Employee name along with his SSN and Supervisor SSN.
select First_Name , Mid_Name ,Last_Name , SSN_Number ,Supervisor_SSN from
employee;

4)Display the employee names whose bdate is ’29-MAR-1959’.


select First_Name , Mid_Name ,Last_Name from employee where
Birthday='1959-03-29';

5)Display salary of the employees without duplications.


select distinct Salary from employee;
6)Display the MgrSSN, MgrStartDate of the manager of ‘Finance’
department.
select ManagerSSN ,ManageStartDate from Department where
Department_Name='Finance';

7)Modify the department number of an employee having fname as


‘Joyce’ to 5.
UPDATE Employee SET Department_Number=5 WHERE First_Name='Joyce';
8)Alter Table department add column DepartmentPhoneNum of
NUMBER data type and insert values into this column only.
ALTER TABLE DEPARTMENT ADD CONTACT_NUMBER INT(10);

UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


Department_Number=1;

UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


Department_Number=2;

UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


Department_Number=3;

UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


Department_Number=4;

UPDATE DEPARTMENT SET CONTACT_NUMBER=1234567890 WHERE


Department_Number=5;
9)Alter table orders modify the size of DepartmentPhoneNum.
ALTER TABLE DEPARTMENT MODIFY CONTACT_NUMBER int(11);

10)Modify the field name DepartmentPhoneNum of departments


table to PhNo.
ALTER TABLE DEPARTMENT MODIFY CONTACT_NUMBER int(11);

11)Rename Table Department as DEPT.


RENAME table DEPARTMENT TO DEPT;

12)Alter Table department remove column DepartmentPhoneNum.


ALTER TABLE DEPT DROP COLUMN CONTACT_NUMBER;
DESC DEPT;

13)Create a table COPYOFDEPT as a copy of the table DEPT.


CREATE TABLE COPYOF_DEPT AS SELECT * FROM DEPT;

SELECT * FROM COPYOF_DEPT;


14)Delete all the rows from COPYOF DEPT table.
delete from COPYOF_DEPT;

SELECT * FROM COPYOF_DEPT;

15)Remove COPYOF DEPT table.


DROP TABLE COPYOF_DEPT;

Exercise- II:
ALTERING EXISTING TABLES AND ADDING CONSTRAINTS:
Employee Table:

ALTER TABLE employee MODIFY fname VARCHAR(15) NOT NULL;

ALTER TABLE employee MODIFY lname VARCHAR(15) NOT NULL;

ALTER TABLE employee MODIFY ssn CHAR(9) PRIMARY KEY;

ALTER TABLE employee MODIFY Sex CHECK(Sex IN ('M','F'));

ALTER TABLE employee MODIFY Salary Number(7) DEFAULT 800;

ALTER TABLE employee ADD FOREIGN KEY(dno) REFERENCES dept (dno) ON


DELETE CASCADE;

You might also like