- INSERT 문
123456INSERT INTO DEPARTMENT VALUES(5, '연구', '');INSERT INTO tmember(no, dept, name, sex)VALUES(201812345, '스마트미디어학과', '홍길동', '남');"
- DELETE 문
12345DELETE FROM DEPARTMENTWHERE DEPTNO = 4;DELETE FROM tmemberWHERE dept='사회복지학과';
- UPDATE 문
12345678910111213UPDATE EMPLOYEESETDNO = 3,SALARY = SALARY * 1.05WHEREEMPNO = 2106;UPDATE tmemberSETdept='스마트미디어학과'WHEREno=201892016;
- SELECT 문
1234567891011121314151617181920212223242526272829SELECT * FROM DEPARTMENT;SELECT DEPTNO, DEPTNAME FROM DEPARTMENT;SELECT TITLE FROM EMPLOYEE;SELECT DISTINCT TITLE FROM EMPLOYEE;SELECT * FROM EMPLOYEE WHERE DNO = 2;SELECT * FROM EMPLOYEE WHERE DNO <> 2;SELECT * FROM EMPLOYEE WHERE EMPNAME LIKE '이%';SELECT FLOOR FROM DEPARTMENT WHERE DEPTNAME='영업' OR DEPTNAME='개발';SELECT * FROM EMPLOYEE WHERE SALARY BETWEEN 3000000 AND 4500000;SELECT * FROM EMPLOYEE WHERE SALARY >= 3000000 AND SALARY <= 4500000;SELECT * FROM EMPLOYEE WHERE DNO IN (1, 3);SELECT * FROM EMPLOYEE WHERE DNO NOT IN (1, 3);SELECT EMPNAME, SALARY, SALARY * 1.1 AS NEWSALARY FROM EMPLOYEE;SELECT * FROM EMPLOYEE WHERE MANAGER IS NULL;SELECT * FROM EMPLOYEE WHERE MANAGER IS NOT NULL;SELECT * FROM EMPLOYEE WHERE DNO = 2 ORDER BY SALARY;SELECT * FROM EMPLOYEE WHERE DNO = 2 ORDER BY SALARY DESC;SELECT * FROM EMPLOYEE WHERE DNO = 2 ORDER BY SALARY, NAME;SELECT AVG(SALARY) AS AVGSAL, MAX(SALARY) AS MAXSAL FROM EMPLOYEE;SELECT DNO, AVG(SALARY) AS AVGSAL, MAX(SALARY) AS MAXSAL FROM EMPLOYEE GROUP BY DNO;SELECT DNO, AVG(SALARY) AS AVGSAL, MAX(SALARY) AS MAXSAL FROM EMPLOYEE GROUP BY DNO HAVING AVG(SALARY) >= 2500000;
- CREATE 문
12345678910111213141516171819202122232425262728293031323334CREATE TABLE tmember (no INTEGER NOT NULL,dept TEXT DEFAULT '스마트미디어학과',name TEXT NOT NULL,sex TEXT DEFAULT '여' CHECK(SEX in ('남','여')),hp TEXT UNIQUE,post INTEGER,PRIMARY KEY(no));CREATE TABLE tbook (no INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,title TEXT,author TEXT,publ TEXT,yea INTEGER,isbn TEXT,symb TEXT);CREATE TABLE tlend (bno INTEGER,mno INTEGER,cdate TEXT DEFAULT CURRENT_TIMESTAMP,days INTEGER,PRIMARY KEY(cdate),FOREIGN KEY(bno) REFERENCES tbook(no)on update CASCADEon delete CASCADE,FOREIGN KEY(mno) REFERENCES tmember(no)on update CASCADEon delete set NULL);
- DROP 문
1DROP TABLE employee;
- JOIN 문
12345678910SELECT tlend.mno as hakbun,tmember.name as name,tbook.title as title,tlend.cdate,tlend.daysFROM tlend, tbook, tmemberWHEREtlend.bno = tbook.noANDtlend.mno = tmember.no;
- 오라클 명령
123456789101112SELECT * FROM dba_users; <-- DBA계정만 사용 가능SELECT * FROM all_users; <-- 모든 계정에서 사용 가능SELECT * FROM tab; <-- 테이블 목록 보기DESC DEPARTMENT;CREATE USER KIM IDENTIFIED BY blueskyDEFAULT TABLESPACE usersTEMPORARY TABLESPACE temp;grant connect, resource, create session, create view to KIM;
SQL문 모음
2019. 11. 20. 14:08
Programing/Database
- INSERT 문
- DELETE 문
- UPDATE 문
- SELECT 문
- CREATE 문
- DROP 문
- JOIN 문
- 오라클 명령
'Programing > Database' 카테고리의 다른 글
Database 정리 (0) | 2020.08.02 |
---|---|
Oracle ALTER, DROP, RENAME, ent (0) | 2019.11.18 |
SQLITE 예제 (0) | 2019.10.16 |
데이터베이스 무결성 제약조건 (0) | 2019.10.02 |
데이터베이스 WHERE 조건 (0) | 2019.09.25 |