μμ½
CREATEκΈ°λ₯: μλ‘μ΄ λμμ μμ±νλλ° μ¬μ©λ¨- μμ± λμ μ§μ (λ°μ΄ν°λ² μ΄μ€, μ€ν€λ§, ν μ΄λΈ, index , ν¨μ λ° νλ‘μμ λ±)
database,schema,table,index,function,procedure
1. ν μ΄λΈ
1.1 μ κ· ν μ΄λΈ μμ±
ν μ΄λΈ μμ± μ, 컬λΌλͺ κ³Ό λ°μ΄ν° νμ , PK λ± μ§μ κ°λ₯ μ»¬λΌ μμ± μ, λ°μ΄ν°νμ μ£Όμ(μ°Έκ³ : (DataBase) λ°μ΄ν° νμ )
create table μ€ν€λ§λͺ
.ν
μ΄λΈλͺ
(
column1 varchar(20) not null,
column2 numeric(10, 4),
column3 text,
column4 integer
primary key (column1, column2),
foreign key (column3) reference μ€ν€λ§λͺ
.μ°Έκ³ ν
μ΄λΈλͺ
)1.2 SELECT λ¬Έμ νμ©νμ¬ ν μ΄λΈ μμ±
FROMλ¬Έμμ κ°μ Έμ¨ ν μ΄λΈ λ΄ μ»¬λΌμ μμ±μ κ·Έλλ‘ μμ±CREATE TABLE ASνμ©
create table μ€ν€λ§λͺ
.ν
μ΄λΈλͺ
as
select column1, column2
from schema.table;2. Index
2.1 Index μμ±
idx_nameμ μλ΅ κ°λ₯(μλμΌλ‘ μ§μ΄μ€)
create index on table_name (column1, column2)
create index idx_name on table_name (column1, column2)2.2 Indexμ Primary Key μ°¨μ΄μ
| κ΅¬λΆ | Index | PK |
|---|---|---|
| λͺ©μ | λ°μ΄ν° μ‘°ν κΈ°λ₯ μ±λ₯ ν₯μμ μν΄ νΉμ μ΄ λλ μ΄ μ‘°ν©μ index μμ± | ν μ΄λΈ κ° νμ κ³ μ νκ² μλ³νκΈ° μν΄ PK μ€μ |
| κΈ°λ₯ | ν μ΄λΈμ νΉμ μ΄μ λν κ²μ, μ λ ¬, μ‘°μΈ μ°μ°μ λΉ λ₯΄κ² μνν μ μλλ‘ λμμ€ | PK μ΄ λλ μ΄ μ‘°ν©μ ν μ΄λΈ λ΄ κ³ μ νλ©°, NULL κ° κ°μ§ μ μμ |
| μ©λ | 쿼리 κΈ°λ₯ ν₯μ(APIμμ ν μ΄λΈ μ‘°ν μ νμ©) | λ°μ΄ν° λ¬΄κ²°μ± λ³΄μ₯, RDBSμ μ ν μ΄λΈ κ° κ΄κ³ μ€μ μ νμ© |
| λ¬΄κ²°μ± μ°¨μ΄μ | μ€λ³΅ νμ© λ° Null κ° ν¬ν¨ κ°λ₯(λ¨, Unique Index μ€μ λ κ°λ₯) | μλμΌλ‘ Uniqueμ Not Null μ μ½ ν¬ν¨ |
| μΈλ±μ€ μ°¨μ΄μ | μλμΌλ‘ μΈλ±μ€ μ§μ νμ | κ³ μ Index μμ±νμ¬ λΉ λ₯Έ μ‘°νκ° κ°λ₯ν¨ |
3. λ°μ΄ν°λ² μ΄μ€ μμ±
create database db_name4. μ€ν€λ§ μμ±
- databaseλ μ§μ λ μν
create schema schema_nameμ°Έκ³ μ¬μ΄νΈ