TIL

[2024.9.3] TIL - SQL 마스터 클라스, 코드트리

yolang 2024. 9. 3. 22:33
728x90

📌Todos

  • ✅ SQL마스터 클래스 3까지
  • ✅ 코드트리 1개

SQL 마스터 클라스

# 3 Data Definition Language

🤓 wsl2 + beekeeper 조합을 사용하려고 했는데 database is locked라고 계속 떴다. wsl2에서 막는다고 하는데 다른 조치를 취해줘야 하는 것처럼 보였으나 쉽지 않아 그냥 로컬에 database를 생성했다.

 

# 3.2 CREATE TABLE

CREATE TABLE movies(
	title,
 	released,
 	overview,
 	rating,
 	director
);

 

# 3.3, 3.4 INSERT INTO VALUES

INSERT INTO movies VALUES (
	'The Godfather',
	1980,
	'NICE',
	10,
	'F.F.c'
);

# 위치 명시 버전
INSERT INTO movies(title, rating)
	VALUES('TLOTR II', 10);

 

# 3.5 Data Types

BLOB: Binary Large OBject

SQLite에서 Strict를 이용해 타입을 강제할 수 있으나 Type Affinity

https://stackoverflow.com/a/77298172

 

SQLite does not check Data Types

Dear Stack Overflow Community, I have a little problem here with starting my first attempt to Database-Design. I try to make some Kind of a tabular and try to check out the Basic functions; writing

stackoverflow.com

스택오버플로우에 따르면 완벽하진 않다고 한다.

 

# 3.6 Constraint, 3.7 CHECK Constraint 

UNIQUE, NOT NULL

CHECK(조건)

ex) for_kids INTEGER NOT NULL DEFAULT 0 CHECK(for_kids = 0 OR for_kids = 1)

ex) for_kids INTEGER NOT NULL DEFAULT 0 CHECK(for_kids BETWEEN 0 AND 1)

ex) for_kids INTEGER NOT NULL DEFAULT 0 CHECK(for_kids > 0)

# 3.8 Functions & Recap

Built in SQL functions

https://sqlite.org/lang_corefunc.html

 

Built-In Scalar SQL Functions

The instr(X,Y) function finds the first occurrence of string Y within string X and returns the number of prior characters plus 1, or 0 if Y is nowhere found within X. Or, if X and Y are both BLOBs, then instr(X,Y) returns one more than the number bytes pri

sqlite.org

 

# 3.9 Primary Keys

고유하고 변경 불가능한 를 각 데이터는 가져야 함, 

  • 자연 기본 key(natural primary key) : 자연적으로 다른 데이터와 구분되는 키, 데이터와 논리적으로 연결 됨Todos
  • ✅ SQL마스터 클래스 3까지
  • ✅ 코드트리 1개
  • SQL 마스터 클라스
  • # 3 Data Definition Language
  • 🤓 wsl2 + beekeeper 조합을 사용하려고 했는데 database is locked라고 계속 떴다. wsl2에서 막는다고 하는데 다른 조치를 취해줘야 하는 것처럼 보였으나 쉽지 않아 그냥 로컬에 database를 생성했다.

 

 

# 3.2 CREATE TABLE

CREATE TABLE movies(

 title,

  released,

  overview,

  rating,

  director

);

 

 

# 3.3, 3.4 INSERT INTO VALUES

INSERT INTO movies VALUES (

 'The Godfather',

 1980,

 'NICE',

 10,

 'F.F.c'

);

 

# 위치 명시 버전

INSERT INTO movies(title, rating)

 VALUES('TLOTR II', 10);

 

 

# 3.5 Data Types

BLOB: Binary Large OBject

 

SQLite에서 Strict를 이용해 타입을 강제할 수 있으나 Type Affinity

 

https://stackoverflow.com/a/77298172

 

SQLite does not check Data Types

Dear Stack Overflow Community, I have a little problem here with starting my first attempt to Database-Design. I try to make some Kind of a tabular and try to check out the Basic functions; writing

stackoverflow.com

스택오버플로우에 따르면 완벽하진 않다고 한다.

 

 

 

# 3.6 Constraint, 3.7 CHECK Constraint 

UNIQUE, NOT NULL

 

CHECK(조건)

 

ex) for_kids INTEGER NOT NULL DEFAULT 0 CHECK(for_kids = 0 OR for_kids = 1)

 

ex) for_kids INTEGER NOT NULL DEFAULT 0 CHECK(for_kids BETWEEN 0 AND 1)

 

ex) for_kids INTEGER NOT NULL DEFAULT 0 CHECK(for_kids > 0)

 

# 3.8 Functions & Recap

Built in SQL functions

 

https://sqlite.org/lang_corefunc.html

 

Built-In Scalar SQL Functions

The instr(X,Y) function finds the first occurrence of string Y within string X and returns the number of prior characters plus 1, or 0 if Y is nowhere found within X. Or, if X and Y are both BLOBs, then instr(X,Y) returns one more than the number bytes pri

sqlite.org

 

 

 

# 3.9 Primary Keys

고유하고 변경 불가능한 를 각 데이터는 가져야 함, 

 

  • 자연 기본 key(natural primary key) : 자연적으로 다른 데이터와 구분되는 키, 데이터와 논리적으로 연결 됨
  • 대체 기본 key(surrogate primary key) : 데이터와 전혀 관련 없는 일부러 만든 키 - id 같은
    • AUTOINCREMENT 사용가능

 

 

 

728x90