-- Stergere tabele in cazul in care ele exista:
DROP TABLE IF EXISTS emp;
DROP TABLE IF EXISTS dept;
DROP TABLE IF EXISTS salgrade;

-- Creare tabel dept:
CREATE TABLE dept
(
    deptno INT,
    dname  VARCHAR(20),
    loc    VARCHAR(20),
    CONSTRAINT dept_deptno_pk PRIMARY KEY (deptno)
);
-- Populare tabel dept
INSERT INTO dept VALUES
(10,'ACCOUNTING','NEW YORK'),
(20,'RESEARCH','DALLAS'),
(30,'SALES','CHICAGO'),
(40,'OPERATIONS','BOSTON');

-- Creare tabel emp:
CREATE TABLE emp
(
    empno    INT,
    ename    VARCHAR(20) ,
    job      VARCHAR(20),
    mgr      INT REFERENCES emp(empno),
    hiredate DATE,
    sal      INT,
    comm     INT,
    deptno   INT,
    CONSTRAINT emp_deptno_fk FOREIGN KEY (deptno) REFERENCES dept(deptno),
    CONSTRAINT emp_empno_pk PRIMARY KEY (empno)
);

-- Populare tabel emp
INSERT INTO emp VALUES
(7839,'KING','PRESIDENT',null,'1981-11-17',5000,null,10),
(7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,null,30),
(7782,'CLARK','MANAGER',7839,'1981-06-09',2450,null,10),
(7566,'JONES','MANAGER',7839,'1981-04-02',2975,null,20),
(7788,'SCOTT','ANALYST',7566,'1982-12-09',3000,null,20),
(7902,'FORD','ANALYST',7566,'1981-12-03',3000,null,20),
(7369,'SMITH','CLERK',7902,'1980-12-17',800,null,20),
(7499,'ALLEN','SALESMAN',7698,'1981-02-20',1600,300,30),
(7521,'WARD','SALESMAN',7698,'1981-02-22',1250,500,30),
(7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30),
(7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,0,30),
(7876,'ADAMS','CLERK',7788,'1983-01-12',1100,null,20),
(7900,'JAMES','CLERK',7698,'1981-12-03',950,null,30),
(7934,'MILLER','CLERK',7782,'1982-01-23',1300,null,10);

-- Creare tabel emp:
CREATE TABLE salgrade
(
    grade INT,
    losal INT NULL,
    hisal INT NULL,
    CONSTRAINT salgrade_grade_pk PRIMARY KEY (grade)
);

-- Populare tabel salgrade
INSERT INTO salgrade VALUES (1,700,1200),
(2,1201,1400),
(3,1401,2000),
(4,2001,3000),
(5,3001,9999);





