doc.dev1x.org

SQL

SELECT

SELECT <COLUMN>,,, FROM <TABLE> WHERE <CONDITIONS>,,,

INSERT

INSERT INTO <TABLE> (<COLUMN>,,,) VALUES (<VALUE>,,,);
INSERT INTO <TABLE> VALUES
    (<COL1_VALUE>, <COL2_VALUE>, <COL3_VALUE>,,, ),
    (<COL1_VALUE>, <COL2_VALUE>, <COL3_VALUE>,,, ),
    (<COL1_VALUE>, <COL2_VALUE>, <COL3_VALUE>,,, ),
    :
-- TABLE2の検索結果をTABLE1へINSERT
INSERT INTO <TABLE1> SELECT ... FROM <TABLE2> WHERE ...
-- TABLE2の検索結果を列を指定してTABLE1へINSERT
INSERT INTO <TABLE1> (COLUMN, COLUMN, ...) SELECT ... FROM <TABLE2> WHERE ...

UPDATE

UPDATE <TABLE> SET <COLUMN> = <VALUE> WHERE 条件;

DELETE

DELETE FROM <TABLE> WHERE 条件;

REPLACE (MySQL)

REPLACE INTO <TABLE> (<COLUMN>,,, ) VALUES (<VALUE>) <SELECT>;
REPLACE INTO <TABLE> VALUES (VALUE1[, VALUE2, ...]);

CREATE TABLE

CREATE TABLE IF NOT EXISTS <TABLE_NAME> (
    <COLUMN_NAME>    <TYPE>       NOT NULL,
    PRIMARY KEY (<COLUMN_NAME>)
);

DROP

ALTER

TRUNCATE