SQLD CH.3 SQL 기본

studied byStudied by 0 people
0.0(0)
learn
LearnA personalized and smart learning plan
exam
Practice TestTake a test on your terms and definitions
spaced repetition
Spaced RepetitionScientifically backed study method
heart puzzle
Matching GameHow quick can you match all your cards?
flashcards
FlashcardsStudy terms and definitions

1 / 61

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

62 Terms

1

E.F CODD는 어떤 이론에 따라 관계형 데이터베이스 만들었누?

정규화 이론

New cards
2

어떤 문제가 있었는가

데이터의 일관성 문제를 근본적으로 해결한 데이터베이스 시스템이 관계형 데이터베이스이다

New cards
3

관계형 데이터베이스 테이블 구성요소

필드, 레코드, 스키마

New cards
4

DDL 뭐임?

Data definition language (데이터 정의 언어)
데이트의 구조 즉 스키마를 정의하는 명령어

New cards
5

DML 뭐임?

Data manipulation language(데이터 조작 언어)
조회, 입력, 수정, 삭제 하는 명령어

New cards
6

DCL 뭐임

사용자 접근 권한과 같이 보안과 제어를 다루는 명렁어 ex. GRANT, REVOKE )

New cards
7

DROP

Deletes entire table (table structure + data)
No rollback and cannot be undone

New cards
8

TRUNCATE

Deletes all rows but keeps the table (only removes data)
Rollback X Cannot be undone

New cards
9

DELETE

Removes specific rows from a table based on a condition. Rollback is possible if not yet committed.

New cards
10

What is the execution order/ query flow order?

FROM, WHERE, GROUP, HAVING, SELECT, ORDER BY

New cards
11

FROM

Specifies the table to retrieve the data from

New cards
12

WHERE

Filters rows based on a condition

New cards
13

GROUP BY

Grioups rows with the same values into summary rows

New cards
14

HAVING

Filters grouped records (used with GROUP BY)

New cards
15

ORDER BY

Sorts the result set in ascending ASC- default order or descending DSC order

New cards
16

단일행 함수

하나의 행에 대해서 연산을 수행한 후에 결과를 반환하는 함수

New cards
17

다중행 함수

여러 행에 대해서 연산을 수행하여 결과를 반환하는 함수. 여러 입력 인자에 대해 단일값을 반환한다는 점은 단일행 함수와 같다.

New cards
18

LOWER (arg)

Turns it into lowercase

New cards
19

UPPER (arg)

Turns it into uppercase

New cards
20

CHR

Returns the character that corresponds to a given ASCII code

New cards
21

TRIM

Removes spaces or specific characters from a string.

New cards
22

TRIM (LEADING)

앞쪽 공백 or 캐릭터 제거

New cards
23

TRIM (TAILING)

뒤쪽 공백 or 캐릭터 뺴기

New cards
24

TRIM (BOTH)

양쪽 공백 or 캐릭터 뺴기

New cards
25

LTRIM

왼쪽 끝에서 공백 또는 지정된 문자열 제거한다

New cards
26

RTRIM

오른쪽 끝에서 공백 또는 지정된 문자열 제거한다

New cards
27

SUBSTR ()

Removes part of a string based on a provided starting position and an optional length.
SUBSTR (string, start-position, length)

ex) SELECT SUBSTR (‘Good Morning’, 1,4)
+ Good (selected characters 1-4 from the provided string)

New cards
28

REPLACE

Replaces something within a string. If a replacement value is not provided, it will be deleted.

SELECT REPLACE (‘Good Morning’, ‘Morning’, ‘Afternoon’') FROM DUAL;

= Good Afternoon

New cards
29

ABS

절대값을 반환한다
used to remove negative signs in calculations

Ex. SELECT ABS(-2.3) FROM DUAL;
= 2.3

New cards
30

MOD

Returns the remainder of a division operation

ex MOD (10,3) FROM DUAL;
= 1
Since 10/3= 3 with 1 left

New cards
31

ROUND

Rounds to a specified decimal place (if the number of decimal places is not specified, it rounds to a digit)

ex)

ROUND(2.67, 1) FROM DUAL;
=2.7 (round to 1 decimal place)

ex) ROUND(2.67)
= 3

New cards
32

TRUNC

Does the same as ROUND but doesn’t round based on numerical value, just cuts of the number at a specified point.
If no value is provided, it gets rid of the decimal places

Ex)
TRUNC(2.37, 1) FROM DUAL;
= 2.3

Ex)
TRUNC(2.37) FROM DUAL;
=2

New cards
33

CEIL

CEILING
Returns the smallest integer greater than or equal to the given number

Ex) SELECT CEIL (4.3) FROM DUAL;
= 5
5 is the smallest integer that is smaller than or equal to 4.3

New cards
34

FLOOR

Same as CEIL but the opposite. Finds the largest integer that is less than or equal to the given number

Ex)
SELECT CEIL (4.3) FROM DUAL;
=4

New cards
35

SYSDATE

Provides the current date and time
Returns this based on the database server where the query is executed.

New cards
36

EXTRACT

Extracts the year, month or day from the date

Ex)
It is the 19th of Feb, 2024

SELECT EXTRACT (YEAR FROM SYSDATE) AS YEAR FROM DUAL;
=2024

New cards
37

변환함수 (Conversion Functions)

Used to convert between different data types such as strings, dates and numbers in SQL

New cards
38

TO_NUMBER

Convers string values or date values to numeric values (integers or decimals)

Ex)
SELECT TO_NUMBER (‘1001’) AS MEMBER_ID FROM DUAL;

= 1001

New cards
39

TO_CHAR

Converts a number or date value to a character string

New cards
40

TO_DATE

Converts the data type to a date

New cards
41

NULL 관련 함수

Provides ways to return specific values when encountering NULL

New cards
42

NVL()

Replaces NULL with a default value.
If the expression is NULL, it will return the specified replacement value. If it is not, it will return the expression’s value.

Ex

SELECT NVL (Salary, 0) FROM employees;
If salary is NULL will return as 0
If not null, the actual salary will pop up

HELPS CHECK FOR NULLS

New cards
43

NULLIF ()

Compares two expressions and returns NULL if they are equal. If they are not equal, it will return the first expression.

Ex

SELECT EMPNO, ENAME, MGR, NULLIF (MGR,7698) AS NM FROM EMP;

If MGR equals 7698 then it will return as NULL

If they aren’t equal the value of MGR will be returned

New cards
44

COALESCE

Returns the first non-NULL value in the list of expressions
It is useful when you wan to select a value from a list and one is NULL, it will return the next one

Ex
COALESCE (NULL,NULL,50,10)
= 50

New cards
45

CASE

Used to perform conditional logic. It allows you to return different values based on different/certain conditions.

Ex
SELECT MOVIE_CODE
CASE
WHEN MOVIE_CODE = ‘01’ THEN ‘COMEDY’
WHEN MOVIE_CODE = ‘02’ THEN ‘SF’
WHEN MOVIE_CODE= ‘03’ THEN ‘ACTION’
ELSE ‘etc’
END AS MOVIE_GENRE
FROM MOVIE;

Corresponding movie codes will be assigned a genre and if not will be labeled ‘etc’.

CAN ALSO USE ‘THEN’ INSTEAD OF ‘=’

New cards
46

단일행 부정 연산자

Compare a single value against a condition (negatively) / it isn’t smtg
Operators: !=, <>, NOT BETWEEN A AND B, NOT LIKE

Ex.
SELECT ename, sal 

FROM emp 

WHERE sal != 3000; OR sal <> 3000 

Retrieves employees whose salary is NOT 3000 


New cards
47

다중행 부정 연산자

Compares multiple values returned by a subquery

Operators: NOT IN, <> ALL

Ex. NOT IN 

SELECT ename, deptno

FROM emp 

WHERE deptno NOT IN (10, 20, 30) 

Retrieves employees who are not in departments 10, 20 or 30 


New cards
48

Logical Operators (논리 연산자)

Operators: AND, OR, NOT 

Ex. AND  (Both conditions must be true) 

SELECT ename, sal, deptno 

FROM emp 

WHERE sal > 2000 AND deptno = 10 ; 

Retrieves employees whose salary is greater than 2000 and who work in department 10 


New cards
49

GROUP BY

Used to group rows that have the same values and perform aggregate functions (집계 함수) on each group

Ex. Find the avg salar per dpt 

SELECT deptno, AVG (sal) 

From emp

GROUP BY deptno ; 

Retrieves the average salary for each department


New cards
50

Aggregate Functions (집계 함수)

Functions that perform calculations on multiple rows at once 

COUNT (*) - Returns the total number of rows 

SUM (column) - Returns the sum of a column 

AVG (column) - Returns the average value 

MIN (column) - Returns the minimum value 

MAX (column) - Returns the maximum value


New cards
51

HAVING

Filtering Grouped Results

AGGREGATED FUNCTIONS REQUIRE HAVING not WHERE

Unlike WHERE, which filters individual rows, HAVING filters GROUPEDDD results (already grouped) 

Ex. Find depts where the average salary is greater than 3000 

SELECT deptno, AVG (sal) 

FROM emp 

GROUP BY deptno 

HAVING AVG (sal) >= 3000 ; 

Retrieves departments where the average salary is greater than 3000 


New cards
52

Single-Row Negative Comparison Operators / simp

!=, <>, NOT BETWEEN, NOT LIKE 

Compare a single value (negatively)

New cards
53

Multi-Row Negative Comparison/ simp

NOT IN, <> ALL 

Compare against multiple values 

New cards
54

Negative Operators/ simp

NOT 

Apply negation to conditions 

New cards
55

Logical Operators/ simp

AND, OR, NOT 

Combine conditions logically 

New cards
56

GROUP BY/ simp

Group rows for aggregate functions

New cards
57

Aggregate functions/ simp

COUNT, SUM, AVG, MIN, MAX 

Summarises data 


New cards
58

HAVING/ simp

Filters grouped data

New cards
59
New cards
60
New cards
61
New cards
62
New cards
robot