공통점
차이점
CREATE TABLE topic(
id INT(11) NOT NULL AUTO_INCREMENT,
title VARCHAR(100) NOT NULL,
description TEXT NULL,
created DATETIME NOT NULL,
author VARCHAR(30) NULL,
profile VARCHAR(30) NULL
, PRIMARY KEY(id));
SHOW DATABASES를 해서 수정하고자 하는 데이터베이스를 찾고
SHOW TABLES를 해서 테이블을 본다
DESC 테이블이름 하면 내부의 값들을 나열된 상태로 볼 수 있다
INSERT INTO topic (title, description, created, author, profile) VALUES('MYSQL', 'MYSQL is …', NOW(), 'egoing', 'developer');
INSERT INTO topic (title, description, created, author, profile) VALUES('ORACLE', 'ORACLE is …', NOW(), 'egoing', 'developer');
INSERT INTO topic (title, description, created, author, profile) VALUES('SQL Server', 'SQL Server is …', NOW(), 'duru', 'data administrator');
INSERT INTO topic (title, description, created, author, profile) VALUES('PostgreSQL', 'PostgreSQL is …', NOW(), 'taeho', 'data scientist, developer');
INSERT INTO topic (title, description, created, author, profile) VALUES('MongoDB', 'MongoDB is …', NOW(), 'egoing', 'developer');
적용된거 보기
SELECT * FROM topic;
(원래 Oracle → ORACLE 임)
(잘모르는건 “SQL SELECT syntax” 검색 후 찾아보기)
밑에와 같은 형식으로 SELECT를 활용할 수 있다
id, title, created, author를 topic에서부터 보여주기
SELECT id, title, created, author FROM topic;
id, title, created, author를 topic에서부터 보여주는데 author는 egoing 이어야함
SELECT id, title, created, author FROM topic WHERE author = 'egoing';
id, title, created, author를 topic에서부터 보여주는데 author는 egoing 이어야하고 역정렬로 출력
SELECT id, title, created, author FROM topic WHERE author = 'egoing' ORDER BY id DESC;
id, title, created, author를 topic에서부터 보여주는데 author는 egoing 이어야하고 역정렬로 출력하는데 첫 2개만
SELECT id, title, created, author FROM topic WHERE author = 'egoing' ORDER BY id DESC LIMIT 2;
위와같이 조건들을 넣어서 SELECT문을 활용해 출력할 수 있다.
Update는 특정 데이터를 수정할 때 쓰는 명령어이다
UPDATE topic SET description='Oracle is ...', title = 'Oracle' WHERE id=2;
Delete는 특정 데이터를 삭제할 때 사용하는 명령어이다
DELETE FROM topic WHERE id = 5;