MySQL Query Notes


1. Create table
CREATE TABLE table1 (
id INT NOT NULL AUTO_INCREMENT,
col1 VARCHAR(30) NOT NULL,
col2 VARCHAR(30) NULL,
createdAt DATETIME,
PRIMARY KEY(id),
);
CREATE TABLE table2 (
id INT NOT NULL AUTO_INCREMENT,
id_table1 INT,
col1 VARCHAR(255) NULL,
createdAt DATETIME,
PRIMARY KEY(id),
INDEX (id_table1),
FOREIGN KEY (id_table1) REFERENCES table1(id)
);

2. Delete table
DROP TABLE tablename;

3. Insert data
INSERT INTO tablename (col1,col2) VALUES ('abc','def');
4. Update data
UPDATE tablename set col1='axe' WHERE col2='def';
5. Delete data
DELETE FROM tablename WHERE col2='def';