- -Department: Department number, department name, address;
- --Employees: Employee number, employee name, job title, management number, entry date, salary, bonus, department number;
CREATE TABLE Dept ( deptno INT PRIMARY key,dname varchar (), loc VARCHAR) ; CREATE TABLE emp (empno INT PRIMARY key,ename VARCHAR () not NULL, job VARCHARCHECK (' clerk ' , ' salesman ', ' MANAGER ', ' ANALYST '), MGP INT, hiredate DATE, sal decimal (10,2), Comm Decimal ( 10,2), deptno INT, CONSTRAINT pk_we FOREIGN KEY (deptno) REFERENCES Dept (deptno) )
Insert data:
INSERT into Dept VALUES (' ACCOUNTING ', ' newtork '); INSERT into Dept VALUES (' DALLAS ', ' the '); INSERT into Dept VALUES (' SALES ', ' CHICAGO '); INSERT into Dept VALUES (Max, ' OPERATIONS ', ' BOSTON '); Select*From Deptinsert into EMP values (7369, ' SMITH ', ' clerk ', 7902, ' 1980-12-17 ', 1640,null,20); INSERT into EMP values (7499, ' ALLEN ', ' salesman ', 7698, ' 1981-2-20 ', 11400,300,30); insert into Empvalues (7521, ' WARD ', ' salesman ', 7698, ' 1981-2-22 ', 5200,500,30); insert into Empvalues (7566, ' joens ', ' MANAGER ', 7839, ' 1981-4-2 ', 7015,null,20); INSERT into EMP values (7654, ' MARTIN ', ' salesman ', 7698, ' 1981-9-28 ', 5200,1400,30); insert into Empvalues (7698, ' BLAKE ', ' MANAGER ', 7839, ' 1981-5-1 ', 5900,null,30); insert into Empvalues (7782, ' CLARK ', ' MANAGER ', 7839, ' 1981-6-9 ', 2470,null,10); INSERT into EMP values (7788, ' SCOTT ', ' ANALYST ', 7566, ' 1987-4-19 ', 3040,null,20);
Select A.ename from EMP a
where exists (SELECT * from dept b where B.deptno=a.deptno and b.deptno=10);
Oracle Department Employee inquiries