DB
-
primary key & Foreign KeyDB/Postgresql(DB) 2023. 11. 27. 17:05
1. Primary Key - FK - 코드 정리 더보기 // 회원 조회 SELECT * FROM USERS; -- users 테이블 CREATE TABLE users( id SERIAL PRIMARY KEY, -- PK 선언(SERIAL:자동 생성 타입) nickname VARCHAR(50), email VARCHAR(100) ); -- users 레코드 등록 INSERT INTO users(nickname,email) VALUES ('cloudstudying_kr', 'mail@cloudstudying.kr'), ('hongpark_cs', 'sehongpark@cloudstudying.kr'), ('haesamq', 'haesamq@naver.com') ; -- photos 테이블 생성 CREATE..
-
시간값 필터필(타임스탬프,extract,to_char)DB/Postgresql(DB) 2023. 11. 27. 16:13
더보기 -- 전체 조회 SELECT * FROM transactions ; -- A. 거래 내역의 총합은? SELECT SUM(amount) -- amunt 컬럼의 총합을 계산 FROM transactions ; -- B. 최대 거래 금액과 최저 거래 금액은? SELECT MAX(amount), -- 최대 거래 금액 min(amount) -- 최소 거래 금액 FROM transactions ; -- C. “Google”과 거래한 총 횟수는? SELECT -- 3 COUNT(*) FROM -- 1 transactions WHERE msg = 'Google' -- 2 ; -- D. 거래 내역의 평균 금액은? SELECT ROUND(AVG(amount),2) -- 평균값 계산 후, 소수점 이하 둘째자리에서 반..
-
WHERE 절DB/Postgresql(DB) 2023. 11. 27. 12:11
예시 더보기 -- 학생 테이블 생성 CREATE TABLE students ( id INTEGER, -- 학생 id nickname VARCHAR(50), -- 닉네임 math_score INTEGER, -- 수학 성적 english_score INTEGER, -- 영어 성적 programming_score INTEGER -- 프로그래밍 성적 ); -- 학생 레코드 추가 INSERT INTO students(id, nickname, math_score, english_score, programming_score) VALUES (1, 'Sparkles', 98, 96, 93), (2, 'Soldier', 82, 66, 98), (3, 'Lapooheart', 84, 70, 82), (4, 'Slick', ..
-
DB 구문 기본 ( CRUD)DB/Postgresql(DB) 2023. 11. 27. 11:59
-- 주석: 실행되지 않는 쿼리(설명을 위함) -- 테이블 생성 쿼리(SQL 명령) CREATE TABLE burgers ( id INT, -- id(숫자) name VARCHAR(50), --이름(최대 50글자) price INT,-- 가격(숫자) gram INT, -- 무게(숫자) kcal INT, -- 열량(숫자) protein INT -- 단백질량(숫자) ); -- 생성 쿼리#1 INSERT INTO burgers(id, name, price, gram, kcal, protein) VALUES (1, '행운버거 골드 스페셜', 6000, 227, 699, 26) -- 행운버거 어서오고 ; -- 생성 쿼리#2 INSERT INTO burgers(id, name, price, gram, kcal, p..
-
oracle XE 데이터베이스 재시작 명령어DB/Oracle(DB) 2023. 11. 1. 15:12
Oracle XE 데이터베이스를 Ubuntu에서 재시작하는 방법은 다음과 같습니다: 1. `service` 명령어를 사용하여 Oracle XE 서비스를 재시작합니다. sudo service oracle-xe restart 2. 만약 `systemctl`을 사용하는 Ubuntu 16.04 이상을 사용하고 있다면 다음과 같이 실행할 수 있습니다. sudo systemctl restart oracle-xe 이러한 명령어들은 관리자 권한(`sudo`)으로 실행되어야 합니다. .
-
MicroSoft - Sql문법DB/Mysql(DB) 2023. 10. 18. 12:07
SELECT stockcd,count(*) FROM biitm01t group by stockcd having count(*) >= 100; -- having은 조건절 --where itemgbn1 ='10' --where itemnm like '%CASE%' --AND (pogbn = '3' or pogbn = '1'); --AND pogbn in('1','3') --where (itemkind = 3 and pogbn = 1) or (itemkind = 2 and pogbn = 2); --where codekind = '102' and (code='2' or code = '3') --where codekind = '102' --where itemkind = 3 --where codekind like ..
-
Mysql(MySQL Workbench) 사용 과 기본 값들DB/Mysql(DB) 2023. 10. 18. 09:18
- MySQL에서 사용되는 다양한 용어들에 대한 설명은 다음과 같습니다: - PK (Primary Key): 기본키로, 각 행을 고유하게 식별하는 역할을 합니다. 즉, 중복된 값을 가질 수 없으며, NULL 값을 가질 수 없습니다. 하나의 테이블에는 하나의 기본키만 존재할 수 있습니다. - NN (Not Null): 해당 열에는 NULL 값을 허용하지 않음을 나타냅니다. 즉, 반드시 값이 존재해야 합니다. - UQ (Unique): 해당 열에 중복된 값을 가지지 않도록 보장합니다. 즉, 모든 값은 유일해야 합니다. - B (Binary): 이진 데이터를 저장할 수 있는 형식입니다. - UN (Unsigned): 해당 열이 양수만을 저장할 수 있음을 나타냅니다. 즉, 음수 값은 허용되지 않습니다. - ZF..
-
Oracle key 종류!DB/Oracle(DB) 2023. 9. 11. 09:34
기본 키 (Primary Key): 기본 키는 테이블 내에서 각 행을 고유하게 식별하는 역할을 합니다. 기본 키는 NULL 값을 가질 수 없습니다. 테이블당 한 개의 기본 키만 설정할 수 있습니다. 외래 키 (Foreign Key): 외래 키는 한 테이블의 열이 다른 테이블의 기본 키를 참조하는 경우 사용됩니다. 외래 키 관계를 통해 두 테이블 간의 관계를 설정하고 유지할 수 있습니다. 고유 제약조건 (Unique Constraint): 고유 제약조건은 특정 열에 대해 중복된 값을 허용하지 않습니다. 즉, 해당 열의 값은 모두 고유해야 합니다. 체크 제약조건 (Check Constraint): 체크 제약조건은 특정 열에 저장될 수 있는 데이터의 유효성을 검사합니다. 예를 들어, 나이 열에는 음수 값이 올..