This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| webseite:mysql:basic [2014/05/27 14:49] – created lunetikk | webseite:mysql:basic [2018/12/20 17:40] (current) – Discussion status changed lunetikk | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== MySQL Basics ====== | ====== MySQL Basics ====== | ||
| - | ^Code^What it does^ | + | ==== Data Definition Language (DDL) ==== |
| + | |||
| + | ^^^ | ||
| + | | CREATE | ||
| + | | ALTER | alters / change the structure of the db | | ||
| + | | DROP | delete objects from the db | | ||
| + | |||
| + | ==== Data Manipulation Language (DML) ==== | ||
| + | |||
| + | ^^^ | ||
| + | | SELECT | ||
| + | | INSERT | ||
| + | | UPDATE | ||
| + | | DELETE | ||
| + | |||
| + | ===== Basics ===== | ||
| + | ^ Code ^ Function | ||
| + | | CREATE TABLE Personal (Lastname CHAR(50) Firstname CHAR(50) Rank VARCHAR(30) Salary (INT)); | ||
| + | | INSERT INTO Personal (Lastname, Firstname) VALUES (' | ||
| + | | UPDATE Personal SET Salary=3200 WHERE Lastname = " | ||
| + | | DELETE FROM Personal WHERE Lastname = " | ||
| + | | DROP TABLE Personal; | ||
| + | | ALTER TABLE Personal ADD Gender CHAR (1); | Add a new column Gender | ||
| + | | SELECT Lastname, Firstname FROM Personal ORDER BY Lastname; | ||
| + | | SELECT Rank FROM Personal GROUP BY Rank; | Shows the ranks grouped | ||
| + | | SELECT COUNT(*) FROM table; | ||
| + | | SELECT * FROM table WHERE field LIKE ' | ||
| + | | SELECT a.name, a.age, b.address FROM table1 a, table2 b WHERE a.id = b.id; | You can use this instead of inner join | | ||
| + | |||
| + | |||
| + | ===== Code examples ===== | ||
| + | ^ | ||
| | SELECT * FROM Table WHERE Cell LIKE ' | | SELECT * FROM Table WHERE Cell LIKE ' | ||
| + | | SELECT IdX FROM Table WHERE Cell LIKE ' | ||
| + | | SELECT * FROM Table ORDER BY IdX DESC LIMIT 0,10 | select all rows limited by 10, order everything by IdX and from newest top to oldest bottom | ||
| + | | SELECT * FROM Table WHERE Cell LIKE ' | ||
| + | | UPDATE `DB`.`Table` SET `Cell1` = ' | ||
| + | | INSERT INTO Table (Cell1, Cell2) VALUES (' | ||
| + | |||
| + | \\ | ||
| + | \\ | ||
| + | ~~DISCUSSION: | ||