Sie sind auf Seite 1von 10

Ques 1.

Design the following table: a)proj1999(projNo, loc, customer ) SQL> create table proj1999( 2 projno Number(10), 3 loc varchar2(10), 4 customer varchar2(10), 5 primary key(projno) 6 ); Table created. b) proj2000 (projno, loc, customer ) SQL> create table proj2000( 2 projno Number(10), 3 loc varchar2(10), 4 customer varchar2(10), 5 primary key(projno) 6 ); Table created. c) parts(partno,partdesc,vendor,cost) SQL> create table parts( 2 partno number(10), 3 partdesc varchar2(10), 4 vendor varchar2(10), 5 cost number(4,2), 6 primary key(partno) 7 ); Table created.

d) department(deptno, deptname) SQL> create table department( 2 deptno number(10), 3 deptname varchar2(10), 4 primary key(deptno) 5 ); Table created. e) employee(empno,ename,deptno,projno,salary) SQL> create table employee( 2 empno number(10), 3 ename varchar2(10), 4 deptno number(10), 5 projno number(10), 6 salary number(10), 7 primary key(empno), 8 foreign key(projno) 9 references proj2000(projno) 10 ); Table created. SQL> alter table employee add foreign key(deptno) references department(deptno); Table altered. f) prjparts(projno,partno,qty) SQL> create table prjparts( 2 projno Number(10), 3 partno number(10), 4 qty number(10), 5 primary key(projno,partno) 6 );

Table created. 2) Insert records into proj1999. SQL> insert into proj1999 values (1,'miami','stocks'); 1 row created. SQL> insert into proj1999 values (2,'Orlando','Allen'); 1 row created. SQL> insert into proj1999 values (3,'Trenton','smith'); 1 row created. 3) Insert records into proj2000. SQL> insert into proj2000 values (1,'miami','stocks'); 1 row created. SQL> insert into proj2000 values (3,'Trenton','smith'); 1 row created. SQL> insert into proj2000 values (5,'Phonix','Robins'); 1 row created. SQL> insert into proj2000 values (6,'Edison','Show'); 1 row created. SQL> insert into proj2000 values (7,'Seattle','Douglas'); 1 row created.

4)Insert records into parts. SQL> insert into parts values (11,'Nut','Richards',19.95); 1 row created. SQL> insert into parts values (22,'Bolt','Black',5.00); 1 row created. SQL> insert into parts values (33,'Washer','Mobley',55.99); 1 row created. 5) Insert records into department. SQL> insert into department values (10,'Production'); 1 row created. SQL> insert into department values (20,'Supplies'); 1 row created. SQL> insert into department values (30,'Marketing'); 1 row created. 6)Insert records into employee. SQL> insert into employee values (101,'carter',10,1,25000); 1 row created.

SQL> insert into employee values (102,'albert',20,3,37000); 1 row created. SQL> insert into employee values (103,'breen',30,6,50500); 1 row created. SQL> insert into employee values (104,'Grould',20,5,23700); 1 row created. SQL> insert into employee values (105,'barker',10,7,75000); 1 row created. 7)Insert records into prjparts. SQL> insert into prjparts values (1,11,20); 1 row created. SQL> insert into prjparts values (2,33,5); 1 row created. SQL> insert into prjparts values (3,11,7); 1 row created. SQL> insert into prjparts values (1,22,10); 1 row created.

8)Print all the tables. SQL> select * from proj1999; PROJNO LOC CUSTOMER ---------- ---------- ---------1 miami stocks 2 Orlando Allen 3 Trenton smith SQL> select * from proj2000; PROJNO LOC CUSTOMER ---------- ---------- ---------1 miami stocks 3 Trenton smith 5 Phonix Robins 6 Edison Show 7 Seattle Douglas SQL> select * from parts; PARTNO PARTDESC VENDOR ---------- ---------- ---------- ---------11 Nut Richards 19.95 22 Bolt Black 5 33 Washer Mobley 55.99 SQL> select * from department; COST

DEPTNO DEPTNAME ---------- ---------10 Production 20 Supplies 30 Marketing SQL> select * from employee; EMPNO ENAME DEPTNO PROJNO ---------- ---------- ---------- ---------- ---------101 carter 10 1 25000 102 albert 20 3 37000 103 breen 30 6 50500 104 Grould 20 5 23700 105 barker 10 7 75000 SQL> select * from prjparts; PROJNO PARTNO ---------- ---------- ---------1 11 20 2 33 5 3 11 7 1 22 10 2 11 3 QTY SALARY

9)Find out the names of all employees. SQL> select ename from employee; ENAME ---------carter albert breen

Grould barker

10) Retrieve employee names and their respective departments.. SQL> select ename ,deptname 2 from employee e,department d 3 where e.deptno=d.deptno; ENAME DEPTNAME ---------- ---------carter Production albert Supplies breen Marketing Grould Supplies barker Production 11) Find the name of employees starting with b. SQL> select ename from employee 2 where ename like 'b%'; ENAME ---------breen barker

12) List the various customers. SQL> (select customer from proj1999)union(select customer from proj2000); CUSTOMER ---------Allen Douglas Robins Show smith stocks 6 rows selected. 13) Find the employees working in PRODUCTION department. SQL> select empno,ename,d.deptno,e.deptno,deptname 2 from employee e,department d 3 where e.deptno=d.deptno 4 and d.deptname = 'production'; EMPNO ENAME DEPTNO ---------- ------------------------- ---------- ---------DEPTNAME ------------------------DEPTNO

101 carter production 105 barker production

10 10

10 10

14) List the employees having salary greater than 40K. SQL> select * from employee 2 where salary>40000; EMPNO ENAME DEPTNO PROJNO ---------- ---------- ---------- ---------- ---------103 breen 30 6 50500 105 barker 10 7 75000 SALARY

15) Determine and maximum and minimum cost of part. SQL> select max(cost),min(cost) from parts; MAX(COST) MIN(COST) ---------- ---------55.99 5

Das könnte Ihnen auch gefallen