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

Assignment DWH

Assignment dataware house

Uploaded by

MUSTAFA HAFEEZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
44 views

Assignment DWH

Assignment dataware house

Uploaded by

MUSTAFA HAFEEZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 11
0130122, 2:21 AM Loading [<= Search mor Souns Answer Short Summary: Provided the Creation of a database called COMPANY and used that database to Create tables Employee, Department, Dept_Locations, Project, Works_On and Dependent. | have done Insertion of records into all these tables ‘Answer: -- create database COMPANY create database COMPANY; - ensure that COMPANY database is used use COMPANY; -~- create table EMPLOYEE with below attributes, respective data types, not null constraints, primary key ‘CREATE TABLE EMPLOYEE ( Fname varchar(15), Minit varchar(1), Lname varchar(15), Ssn char(9) NOT NULL, Bdate date, Address varchar(50), Sex char(1), creativeworks.llstorytelingnumber-one-ski-improve! wm 90722, 221 AM Loading Salary decimal(10,2), Super_ssn char(9), Dno int, PRIMARY KEY (Ssn) % -- create table DEPARTMENT with below attributes, respective data types, not null constraints, primary and foreign key CREATE TABLE DEPARTMENT ( Dname varchar(25), Dnumber int NOT NULL, Mgr_ssn char(9), Mgr_start_date date, PRIMARY KEY (Dnumber), FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn) on delete cascade on update cascade x -- alter table EMPLOYEE to add foreign keys ALTER TABLE EMPLOYEE ADD ( FOREIGN KEY (Dno) REFERENCES DEPARTMENT(Dnumber) on delete cascade on update cascade, FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn) on delete cascade on update cascade); -- create table DEPT_LOCATIONS with below attributes, respective data types, not null constraints, primary and foreign key CREATE TABLE DEPT_LOCATIONS ( Dnumber int NOT NULL, Dlocation varchar(15) NOT NULL, PRIMARY KEY (Dnumber, Dlocation), creativeworks.llstoryeling-number-one-ski-improve! amt 0130122, 2:21 AM Loading FOREIGN KEY (Dnumber) REFERENCES DEPARTMENT(Dnumber) on delete cascade on update cascade yi -- create table PROJECT with below attributes, respective data types, not null constraints, primary and foreign key CREATE TABLE PROJECT ( Pname varchar(25), Pnumber int NOT NULL, Plocation varchar(15), Dnum int NOT NULL, PRIMARY KEY (Pnumber), FOREIGN KEY (Dnum) REFERENCES DEPARTMENT(Dnumber) on delete cascade on update cascade \ -- create table WORKS_ON with below attributes, respective data types, not null constraints, primary and foreign key CREATE TABLE WORKS_ON ( Essn char(9) NOT NULL, Pno int NOT NULL, Hours decimal(4,1), PRIMARY KEY (Essn, Pro), FOREIGN KEY (Essn) REFERENCES EMPLOYEE(Ssn), FOREIGN KEY (Pno) REFERENCES PROJECT(Pnumber) on delete cascade on update cascade x -- create table DEPENDENT with below attributes, respective data types, not null constraints, primary and foreign key CREATE TABLE DEPENDENT ( creativeworks.llstoryeling-number-one-ski-improve! amt 10730722, 221 AM Loading Essn char(9) NOT NULL, Dependent_name varchar(15) NOT NULL, Sex chart), Bdate date, Relationship varchar(8), PRIMARY KEY (Essn, Dependent_name), FOREIGN KEY (Essn) REFERENCES EMPLOYEE(Ssn) on delete cascade on update cascade % -- insert values into EMPLOYEE table INSERT INTO EMPLOYEE VALUES (James’,E,Borg’'888665555;,1937-11-10'450 Stone, Houston, TX',M’,55000,null,null); INSERT INTO EMPLOYEE VALUES (Franklin’,T','Wong},'333445555','1955-12-08','638 Voss, Houston, TX’,'M',40000,'888665555',null); INSERT INTO EMPLOYEE VALUES ', Wallace’,'987654321''1941-06-20'/291 Berry, Bellaire, TX','F,43000,'888665555',null); (Jennifer, -- insert values into DEPARTMENT table INSERT INTO DEPARTMENT VALUES (‘Research’, 5, '333445555', '1988-05-22'); INSERT INTO DEPARTMENT VALUES (‘Administration’, 4, '987654321', 1995-01-01"); INSERT INTO DEPARTMENT VALUES (‘Headquarters', 1, '888665555', '1981-06-19'); -- update Dno for employees in EMPLOYEE table UPDATE EMPLOYEE SET Dno = 5 WHERE Ssn = '333445555'; creativeworks.llstoryeling-number-one-ski-improve! an 0130122, 2:21 AM Loading UPDATE EMPLOYEE SET Dno = 4 WHERE Ssn = “987654321'; UPDATE EMPLOYEE SET Dno = 1 WHERE Ssn = '888665555'; -- insert values into EMPLOYEE table INSERT INTO EMPLOYEE VALUES (‘John’, ‘TX;,M‘,30000,'333445555',5); *Smith’,'123456789','1965-01 -09','731 Fondren, Houston, INSERT INTO EMPLOYEE VALUES (‘Alicia’, ‘TX;;F,25000,'987654321'4); elaya’,'999887777','1968-01-19',3321 Castle, Spring, INSERT INTO EMPLOYEE VALUES (‘Ramesh’ Humble, TX’,'M',38000,'333445555',5); *Narayan’,'666884444','1962-09-15','971 Fire Oak, INSERT INTO EMPLOYEE VALUES (‘Joyce’,’A’,English’,453453453",'1972-07-31,,'5631 Rice, Houston, TX,;F',25000,'333445555',5); INSERT INTO EMPLOYEE VALUES (‘Ahmad','V',Jabbar','987987987','1969-03-29','980 Dallas, Houston, ‘TX,M‘,25000,'987654321',4); -- insert values into PROJECT table INSERT INTO PROJECT VALUES (‘ProductX’,1,'Bellaire’,5); INSERT INTO PROJECT VALUES (‘ProductY’, ‘Sugarland’5); INSERT INTO PROJECT VALUES ('ProductZ’,3,'Houston’,5); INSERT INTO PROJECT VALUES (‘Computerization’,10,'Stafford’,4); INSERT INTO PROJECT VALUES (‘Reorganization’,20,'Houston’,1); INSERT INTO PROJECT VALUES (‘Newbenefits’,30,'Stafford',4); -- insert values into DEPT_LOCATIONS table INSERT INTO DEPT_LOCATIONS VALUES (1,Houston’); creativeworks.llstoryeling-number-one-ski-improve! sit 0130122, 2:21 AM Loading INSERT INTO DEPT_LOCATIONS VALUES (4,’Stafford’); INSERT INTO DEPT_LOCATIONS VALUES (5,'Bellaire INSERT INTO DEPT_LOCATIONS VALUES (5,'Sugarland’); INSERT INTO DEPT_LOCATIONS VALUES (5,'Houston’); -- insert values into WORKS_ON table INSERT INTO WORKS_ON VALUES ('123456789",1, 32.5); INSERT INTO WORKS_ON VALUES ('123456789',2, 7.5); INSERT INTO WORKS_ON VALUES ('666884444',3, 40.0); INSERT INTO WORKS_ON VALUES ('453453453',1, 20.0); INSERT INTO WORKS_ON VALUES ('453453453',2, 20.0); INSERT INTO WORKS_ON VALUES ('333445555',2, 10.0); INSERT INTO WORKS_ON VALUES ('333445555',3, 10.0); INSERT INTO WORKS_ON VALUES ('333445555',10,10.0); INSERT INTO WORKS_ON VALUES ('333445555',20,10.0); INSERT INTO WORKS_ON VALUES ('999887777',30,30.0); INSERT INTO WORKS_ON VALUES ('999887777',10,10.0); INSERT INTO WORKS_ON VALUES ('987987987',10,35.0); INSERT INTO WORKS_ON VALUES ('987987987',30, 5.0); INSERT INTO WORKS_ON VALUES ('987654321',30,20.0); INSERT INTO WORKS_ON VALUES ('987654321',20,15.0); INSERT INTO WORKS_ON VALUES ('888665555',20,null); -- insert values into DEPENDENT table INSERT INTO DEPENDENT VALUES ('333445555",'Alice’,'F','1986-04-05',/Daughter’); INSERT INTO DEPENDENT VALUES ('333445555",'Theodore’,'M','1983-10-25;,'Son)); creativeworks.llstoryeling-number-one-ski-improve! 0130122, 2:21 AM Loading. INSERT INTO DEPENDENT VALUES ('333445555°, Joy’,'F,'1958-05-03',Spouse’); INSERT INTO DEPENDENT VALUES ('987654321",'Abner','M','1942-02-28','Spouse'); INSERT INTO DEPENDENT VALUES ('123456789", ‘Michael’,'M’,'1988-01-04",'Son’); INSERT INTO DEPENDENT VALUES ('123456789",'Alice’,'F’, '1988-12-30',Daughter’); INSERT INTO DEPENDENT VALUES ('123456789",Elizabet! 967-05-05','Spouse’); Screesnshot of query and sample output: - create database COMPANY © create database COMPANYS = ensure that COMPANY databace is used 1 2 3 4 5 © use CONPANY; 6 7 8 _~ create table EMPLOYEE with below attributes, respective data types, not null constraints, primary key 9 © © CREATE TABLE EMPLOYEE ( 10 | Frame varchar(15), 12 | Minit varchar(1), 2 Lname varchar(15), 13 | Ssm char(9) nor Nutt, 14 | date date, 15 Address varchar(50), 16 | Sex char(a), 17 | Salary decimal(10,2), 18 | Super_ssn char(9), 19 | no int, 20 | PRIMARY KEY (Ssn) a % cteativeworkslalistorteling-number-one-ski-improvel mm 0130122, 2:21 AM Loading. 2 20 2 » 36 7 29 o so geesesas 3 ss gaessers 6 = create table DEPARTMENT with below attribut (CREATE TABLE DEPARTTENT ( (nome varchar(25), number int NOT HULLS Ner_ssn chart), Ngr_stact date date, PRIMARY KEY (Onumber)» FOREIGN KEY (Hgr_ssn) REFERENCES EMPLOYEE(SSN) on delete cascade on update cascade , respective data types, not null constraints, primary and foreign key alter table EPLOYEE to add foresgn key [ALTER TABLE EMPLOYEE A00 ( FOREIGN KEY (Ono) REFERENCES DEPARTMENT(Onunber) on delete cascade on update cascade, FOREIGN KEY (Super_ten) REFERENCES EXPLOYEE(Ssn) on delete cascode on update cascade)s = create table DEPT_LOCATIONS with below attributes, respective (CREATE TABLE DEPT_LOCATEONS ( Dumber int NOT HULL, location varchar(15) NOT MULL, Runny KEY (number, Dlocetion), FOREIGN KEY (Onutber) REFERENCES DEPARTHENT(Onuaber) on delete cascade on update cascade » types, not null constraints, primary and foreign key + create table PRODECT with below attributes, respective data types, not null constraints, primary and foreign key > CREATE TABLE PROJECT ( Pane varchar(25)» Prumber int NOT MULLy Placation varchar(18)s ‘Drum int NOT MULL, PaDMARY KEY (Pruners FOREIGH KEY (Drum) REFERENCES DEPARTHENT(Onunber) on delete cascade on update cascade » - create table WORKS 0 with below attributes, respective data types, not null constraints, primary and foreign key (CREATE TABLE MORKS_oH ssn char(9) NOT NULL, Pro int NOT MULL, Wours decinal(#i)s PRIMARY KEY (Es8n» Pro)» FOREIGN KEY (Essn) REFERENCES ENPLOYEE(Ssn), FOREIGN KEY (Pro) REFERENCES PRODECT(Pnumber) on delete cascade on update cascade » ‘cteativeworkslalistoryteling-number-one-skiLimprovel amt 0130122, 2:21 AM Loading. 6 create table O&PEIOENT with below attribute 65 # © CREATE TABLE DEPENDENT ¢ respective data types, not null constraints, primary and foreign key 67 | ssn ehar(s) nor Mitty 63 | Dependent.nore varchar(i5) NOT MLLs 6 | Sex charci), 70 | Bdate date » 71 | Relationship varchar(6 72 | PRONARY KEY (Essny Dependent rane)» 73. | FOREIGN KEY (Essn) REFERENCES EHPLOYEE(SHn) on delete cascade on update cascade 7% | oy * 75 == insert values into EVPLOYEE table 77 © INSERT INTO EMPLOYEE VALUES 78 ("Jmes","€", "Borg" '888665555",'1937-11-16","450 Stone, Houston, TX", "NM" ,55008,nul1 null); 79.8 INSERT INTO EMPLOYEE VALUES 82 Franklin’, ‘T", Wong", "333445555","1955-12-@6","638 Voss, Houston, TX’, "N',40808, "888665555" null); 81 © INSERT INTO EMPLOYEE VALUES, 82 ("Dennifer*,'S', ‘wallace’ ,'987654321",'1961-06-20",'201 Berry, Bellaire, TX",'F’,43600, ‘B8B665555 3 84 -- Ansert values into DEPARTHENT table 85 © INSERT INTO DEPARTMENT VALUES (‘Research’, 5, °333445555', "1985-05-22" 85 © INSERT INTO DEPARTMENT VALUES ("Adwinistration’, 4, 957654321", ‘1995-1-01")s 87 © INSERT INTO DEPARTMENT VALUES ("Headquarters’, 1, "888665555", '1981-96-19') a8 89 = update Ono for employees in EMPLOYEE t 90 © — UPOATE EMPLOYEE 91 SET Dno = 5 92 MERE Ssn = *333845555' 93 © UPDATE ENPLOVEE 94 SET Dno = 4 95 WHERE Ssn = "957654523"s 96 © UPOATE EMPLOYEE 97 SET Dn = 2 98 MHERE Ssn = ‘B30565555'5 9 cteativeworkslalistoryteling-number-one-skiLimprovel om 0130122, 2:21 AM Loading. wee INSERT THT0 EMPLOYEE VALUES (Sohn'y'B',"Saith’ "128455789" "1965-01-09","731 Fondren, Houston, TX's'N’ ,38800,'335445555',5)3 INSERT TITO ERPLOYEE VALUES (‘ALScia’ "9", "Zelayay"990897777","1968-@1-19°,°3221 Castle, Spring, TX's’F"25000,°997654321" 45 INSERT TITO EMPLOYEE VALUES (‘Ranesh’ K's "Marayan'y"666B84444","1962-€3-15'5'973 Fire Oak, Humble, TX' p's 28000, 222443855", 5)5 INSERT THTO EMPLOYEE VALUES (Zoyce'y'A’ English’ »'453455453",'1072-67-31","5631 Ace, Houston, TH','F",25006,"333445555',5)s INSERT TO ERPLOYEE VALUES ("Ahmad y'V" 'Zobbar'y'987387967","1969-83-29","568 Dallas, Houston, TH'y'*” p25008y'987654521's4)5 + insert values Sno PRORECT table ANSERT INTO PRODECT VALUES ("ProductX" 1, "Bellaire’5)3 XNSERT TATD PRODECT VALUES ("ProductY* 2, Sugarland’ 5)5 INSERT TTD PRODECT VALUES ("Productz",3, Houston’ 5)3 ANSERT INTO PRODECT VALUES ("Computerization’ 10, Stafford” o4)s XNSENT INTO PROJECT VALUES (‘Reorganization 20,"Nouston" ADs IWSERT TTD PRODECT VALUES (‘WebeneFLts'20, "Stafford s8)s {INSERT TTD DEPT_LOCATIONS VALUES (Ly Houston") [WSERT TO OEPT_LOCATIONS VALUES (8,"StaFford’)s {INSERT INYO OEPT LOCATIONS VALUES (3,"eLaire’) [NSENT 470 DEPT_LOCATIONS VALUES (5,"Sugprland”)s [WSERT ITO DEPT_LOCATIONS VALUES ($y"Houston’)y _creativeworkslalistoryteling-number-one-ski-improvel son 0130122, 2:21 AM Loading. 122 123 124. 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 aa 142 143 144 145, 146 147 148 -+ insert values into WORKS_ON table INSERT INTO WORKS_ON VALUES ("123456789"41, 32.5)5 INSERT INTO WORKS_ON VALUES ('123456789",2, 7.5)5 INSERT INTO WORKS_ON VALUES ("656884244",3, 40.0); INSERT INTO WORKS_ON VALUES ('453453453",1, 20.0)5 INSERT INTO WORKS_ON VALUES ("453453453",2, 20.0)5 INSERT INTO WORKS_ON VALUES (°333445555"525 10.0)5 INSERT INTO WORKS_ON VALUES ("333445555",3, 10.0)5 INSERT INTO WORKS_ON VALUES ('333445555",10,10.0)5 INSERT INTO WORKS_ON VALUES ('333485555", 20, 10. INSERT INTO WORKS_ON VALUES ('999887777",30,30.0)5 INSERT INTO WORKS_ON VALUES (°999887777" ,12,10.0)5 INSERT INTO WORKS_ON VALUES ("987987987" ,10,35.0)5 INSERT INTO WORKS_ON VALUES ('987987987",3@, 5.0)5 INSERT INTO WORKS_ON VALUES ('957654321'30,20.2)5 INSERT INTO WORKS_ON VALUES ('957654321" ,20,15.0)5 INSERT INTO WORKS_ON VALUES ('888665555", 20, null); -+ insert values into DEPENDENT table INSERT INTO DEPENDENT VALUES (’ 333445555", "Alice’y"F","1986-04-05", Daughter") INSERT INTO DEPENDENT VALUES (°333445555", ‘Theodore’, 'M’ ,°1983-10-25",'Son’)5 INSERT INTO DEPENDENT VALUES (°333445555","Joy*,'F’ "1958-05-03", “Spouse’)s INSERT INTO DEPENDENT VALUES ('987654321', ‘Abner’ y'M" ,'1942-@2-28","Spouse')3 INSERT INTO DEPENDENT VALUES ('123456789', 'Michael',"N’,'1988-61-04','Son'); INSERT INTO DEPENDENT VALUES ('123456789",“Alice','F", °1988-12-30", ‘Daughter"); Likes: 1 Dislikes: 0 INSERT INTO DEPENDENT VALUES ('123456789", "Elizabeth" ,'F’ ,'1967-05-@5', "Spouse")5 ‘cteativeworkslalistoryteling-number-one-ski-improvel an

You might also like