데이터베이스 객체 작성과 삭제

반응형
반응형

1. 데이터베이스 객체

 

Sql-Study-Organization/SQL_Repository

Contribute to Sql-Study-Organization/SQL_Repository development by creating an account on GitHub.

github.com

 

2.  테이블 작성 삭제 변경

    테이블 작성

     CREATE TABLE 테이블명 ( 열 정의1, 열 정의2, ....)
     열명 자료형[DEFAULT 기본값][NULL|NOT NULL]

create한뒤, DESC한 모습

 테이블 삭제

DROP TABLE 
TRUNCATE TABLE :모든 행 삭제 (빠름)

 

테이블 변경

ALTER TABLE 테이블명 변경 명령

        - 열 추가 ADD 열정의

ADD newcol Integer

        - 열 속성 변경 : MOTIFY 열정의

Integer -> varchar

        - 열 이름 변경 : CHANGE 기존 열이름 신규 열 정의

newcol -> c

        - 열 삭제 : DROP 열명

c열 삭제

 

Sql-Study-Organization/SQL_Repository

Contribute to Sql-Study-Organization/SQL_Repository development by creating an account on GitHub.

github.com

 

3. 제약

              - 열 제약

b 열 unique

            

             - 테이블 제약

no, sub_no primary key

결과는 똑같이 나온다...

 

제약 추가

name => not null 추가

 

열 제약 삭제

     

 

 

Sql-Study-Organization/SQL_Repository

Contribute to Sql-Study-Organization/SQL_Repository development by creating an account on GitHub.

github.com

 

4. 인덱스 구조

 

Sql-Study-Organization/SQL_Repository

Contribute to Sql-Study-Organization/SQL_Repository development by creating an account on GitHub.

github.com

 

5. 인덱스 작성과 삭제

    CREATE INDEX 인덱스명 ON 테이블 명 (열명1, 열명2...)

    DROP INDEX 인덱스명 ON 테이블 명

 

 

explain

 

 

Sql-Study-Organization/SQL_Repository

Contribute to Sql-Study-Organization/SQL_Repository development by creating an account on GitHub.

github.com

 

5. 뷰

  CREATE VIEW 뷰명 AS SELECT 명령
  DROP VIEW 뷰명

뷰 사용

 

 

Sql-Study-Organization/SQL_Repository

Contribute to Sql-Study-Organization/SQL_Repository development by creating an account on GitHub.

github.com

 

반응형

'sql' 카테고리의 다른 글

데이터 베이스 설계  (0) 2020.09.11
복수의 테이블 다루기  (0) 2020.09.11
오라클 jdbc  (0) 2020.09.09
집계와 서브쿼리  (0) 2020.09.09
insert,delete,update  (0) 2020.09.09

댓글

Designed by JB FACTORY