SQL (Constraints), PHP (DB Fetch), Concatenation

Hyun Seo (Lucy) Lee 이현서·2020년 9월 29일
0

09/29/2020

SQL

Setting up PKs and FKs

> CREATE TABLE 테이블 (
....
CONSTRAINT 제약조건이름 PRIMARY KEY (column),
CONSTRAINT 제약조건이름 FOREIGN KEY (column)
REFERENCES reference_table (reference_column)
);

OR

> CREATE TABLE 테이블 (
columnname date_type CONSTRAINT 제약조건이름 PRIMARY KEY,
column_name data_type CONSTRAINT 제약
조건_이름 FOREIGN KEY
REFERENCES ref_table (ref_column),
....
);

  • 제약 조건 이름 ex: dept_dno_pk, emp_eno_pk, emp_mgr_fk, etc.
  • 여기서 "CONSTRAINT 제약_조건_이름" 은 생략해도 되긴 되는데 그럼 constraint_name을 검색할때 SYS_COO7131 이런게 나온다.

제약 조건 (Constraint Conditions) 조회

--> 여기서 C 컬럼 밑에 P는 Primary Key, R은 Foreign Key를 뜻함
--> 두번째 example 처럼 p 와 c 로 user_constraints 별명을 나눠쓰면 상위테이블-하위테이블 relationship 을 볼수 있음. 그대신 c.r_constraint_name=p.constraint_name 해줌.

테이블 상세 도표

PHP DB 연동

oci_fetch_array
- used during a while loop, basically deals with only one array at a time and thus only one entry in the data table at a time.
oci_fetch_all
- returns the number of rows in the 2 dimensional array --> which are displayed as columns when drawn on paper, like this:

  • for oci_fetch_all, 공간복잡도가 올라가는 대신 시간복잡도가 내려감. And the opposite for oci_fetch_array.

  • 그리고 when you use oci_fetch_all($result, $row), you can do the oci_free_statement($result) sooner since you already have all the data you need in $row.

Side note: Concatenation

  • in SQL: ||
  • in PHP: .
  • in MySQL: concat() function?

0개의 댓글