sql cookbook
a year ago
a minute read (About 142 words)
Create and Alter user 1 2 CREATE USER '<USER_NAME>' @'localhost' IDENTIFIED BY 'password' ; GRANT ALL ON *.* TO '<USER_NAME>' @'%' WITH GRANT OPTION ;
ALTER TABLE 1 2 3 ALTER TABLE <TABLE_NAME> CHANGE <COLUMN1> <COLUMN2> <DATATYPE> ALTER TABLE <TABLE_NAME> DROP <COLUMN_NAME>ALTER TABLE <TABLE_NAME> MODIFY <COLUMN_NAME> <DATA_TYPE> NOT NULL PRIMARY KEY
INSERT STATEMENT 존재하지 않는 것만 추가하기 1 2 3 4 5 INSERT INTO <TABLE > (<COLUMN1>, <COLUMN2>) VALUES (<VALUE1>, <VALUE2>) WHERE NOT EXISTS ( SELECT <COLUMN > FROM <TABLE2> WHERE id =<value > )
SELECT STATEMENT LIKE 1 SELECT * FROM <table_name> WHERE <COLUMN > LIKE "%<CONTENT>%" ;
ORDER BY 1 SELECT * FROM <TABLE_NAME> WHERE <CONDITION> ORDER BY <COLUMN1> DESC , <COLUMN2> ASC
LIMIT 1 SELECT * FROM <TABLE > LIMIT <INDEX >, <NUMBER >
GROUP BY 1 2 3 4 SELECT u.name, MAX (c.price)FROM user u LEFT JOIN car c ON u.id = c.user_idWHERE u.id = 4 ;GROUP BY u.name
PROBLEM SOLVING where 절 없이 업데이트 실패하는 경우 1 SET SQL_SAFE_UPDATES = 0 ;
Comments