DB 0323

|

UES COMPANY;
CREAT TABLE DEPARTMENT (
DEPTNO  INT NOT NULL.
DEPTNAME CHAR(10).
FLOOR  INT.
PRIMARY KEY (DEPTNO)
);
INSERT INTO DEPARTMENT VALUES(1, '영업', 8);
INSERT INTO DEPARTMENT VALUES(2, '기획', 10);
INSERT INTO DEPARTMENT VALUES(3, '개발', 9);
INSERT INTO DEPARTMENT VALUES(4, '총무', 7);

CREAT TABLE EMPLOYEE (
EMPNO  INT NOT NULL.
EMPNAME  CHAR(10) UNIQUE.
TITLE  CHAR(10) DEFAULT '사원'.
MANAGER  INT.
SALARY  INT CHECK (SALARY < 6000000).
DNO  INT CHECK (DNO IN (1,2,3,4)) DEFAULT 1.
PRIMARY KEY(EMPNO).
FOREIGN KEY(MANAGER) REFERENCES EMPLOYEE(EMPNO).
FOREIGN KEY(DNO) REFERENCES DEPARTMENT(DEPTNO) ON UPDATE CASCADE);

INSERT INTO EMPLOYEE VALUES(4377, '이성래', '사장', NULL, 5000000, 2);
INSERT INTO EMPLOYEE VALUES(3426, '박영권', '과장', 4377, 3000000, 1);
INSERT INTO EMPLOYEE VALUES(3011, '이수민', '부장', 4377, 4000000, 3);
INSERT INTO EMPLOYEE VALUES(3427, '최종철', '사원', 3011, 1500000, 3);
INSERT INTO EMPLOYEE VALUES(1003, '조민희', '과장', 4377, 3000000, 2);
INSERT INTO EMPLOYEE VALUES(2106, '김창섭', '대리', 1003, 2500000, 2);
INSERT INTO EMPLOYEE VALUES(1365, '김상원', '사원', 3426, 1500000, 1);
GO
CREAT VIEW EMP_PLANNING
AS
SELECT E.EMPNAME, E.TITLE, E.SALARY
FROM EMPLOYEE E, DEPARTMENT D
WHERE E.DNO=D.DEPTNO AND D.DEPTNAME='기획'
GO

'메모 > DB' 카테고리의 다른 글

SQL Server 원격 접속 허용하기  (0) 2012.04.01
DB 0330 (date)  (0) 2012.03.30
DB 쿼리1  (0) 2012.03.29
And
prev | 1 | 2 | 3 | 4 | next