데이터베이스 생성
CREATE DATABASE mydb;
유저생성
CREATE USER 'USERNAME'@'HOST' identified by 'password'
테이블 생성
CREATE tablename
(
columnname datatype,
columnname datatype,
...
)
테이블 이름 변경
ALTER TABLE tablename
RENAME new_tablename;
컬럼 추가
ALTER TABLE tablename
ADD COLUMN columnname datatype;
컬럼 데이터타입 변경
ALTER TABLE tablename
MODIFY COLUMN columnname datatype;
컬럼 이름과 데이터타입 변경
ALTER TABLE tablename
CHANGE COLUMN old_columnname new_columnname new_datatype;
컬럼 삭제
ALTER TABLE tablename
DROP COLUMN columnname;
DB 삭제
DROP DATABASE mydb;
유저 삭제
DROP USER 'USERNAME'@'HOST'
테이블 삭제
DROP TABLE tablename;
데이터 추가
INSERT INTO tablename (column1, column2, ...)
VALUES (value1, value2, ...);
데이터 선택
SELECT column1, column2, ...
FROM tablename;
select, update, delete 등의 문법에 조건으로 같이 사용됨
SELECT column1, column2, ...
FROM tablename
WHERE condition;
데이터 수정
UPDATE tablename
SET column1 = value1, column2 = value2, ...
WHERER condition;
데이터 삭제
DELETE FROM tablename
WHERE condition;
SHOW GRANTS FOR 'USERNAME'@'HOST';
GRANT ALL ON DBNAME.* to 'USERNAME'@'HOST';
REVOKE ALL ON DBNAME.* from 'USERNAME'@'HOST';
SHOW TARGET(DB, TABLE 등)
FLUSH PRIVILEGES;
SELECT column1, column2, ...
FROM tablename
ORDER BY column1, column2, ... ASC | DESC;
'_' : 글자의 갯수
'%' : 임의의 글자
select * from celeb
where agency like 'XX%' | '%X%' | '__XXXX%';
SELECT column1, column2, ... FROM table1
UNION ALL | UNION
SELECT column1, column2, ... FROM table2
SELECT column1, column2, ...
FROM table1
INNER | LEFT | RIGHT JOIN table2
ON table1.column = table2.column
WHERE condition;
SELECT CONCAT(column1, column2, ...)
FROM tablename
as는 생략가능
SELECT column as alias
FROM tablename
SELECT A.column
FROM tablename as A
SELECT DISTINCT column1, column2, ...
FROM tablename
SELECT column1, column2 ...
FROM tablename
WHERE condition
LIMIT number;
- Part 05. SQL
- SQL1
- SQL2
- AWS RDS와 SQL File