Mysql Banco de Dados
SELECT * FROM artist; lê os dados de todas as linhas da tabela artist.
SELECT artist_name FROM artist; lê dados da coluna artist_name.
SELECT artist_name, artist_id FROM artist; lê dados da coluna artist_name e artist_id.
WHERE
SELECT * FROM artist WHERE artist_name = “New Order”; lê os dados de todas as linhas da tabela artist onde o artist_name for igual a
New Order.
SELECT artist_name FROM artist WHERE artist_id = 4; lê dados da coluna artist_name onde o artist_id for igual a 4.
SELECT track_name FROM track WHERE track_id = 13; lê dados da coluna track_name onde o track_id for igual a 13.
SELECT artist_name FROM artist WHERE artist_id < 5; lê dados da coluna artist_name onde o artist_id for menor do que 5.
SELECT album_name FROM álbum WHERE album_id <> 2; lê dados da coluna álbum_name onde o álbum_id for diferente de 2. Pode ser usado o sinal != como diferente.
SELECT artist_name FROM artist WHERE artist_name < ‘M’; lê dados da coluna artist_name onde o artist_name for menor que a letra
M do alfabeto.
WHERE
SELECT album_name FROM album WHERE album_name LIKE
“Retro%; lê os dados da coluna album_name onde album_name começa com Retro.
WHERE combinação com AND, OR, NOT
SELECT album_name FROM album WHERE
-> album_name > “C” AND album_name < “M”;
SELECT album_name FROM album WHERE
-> album_name LIKE “L%” OR
-> album_name LIKE “S%” OR
-> album_name LIKE “P%”;
SELECT album_name FROM album WHERE
-> album_name LIKE “L%” OR
-> album_name LIKE “S%” AND
-> album_name LIKE “%g”;
SELECT * FROM album WHERE NOT (album_id = 1 OR album_id =
3);
UPDATE, DELETE
UPDATE album SET album_name = “Substance 1987 (Disc 2)”
WHERE artist_id = 1 AND album_id = 2;
DELETE FROM played;
DELETE FROM played WHERE played < “2006-08-15”;
DELETE FROM artist WHERE artist_id = 3;
UPDATE: modifica dados de uma tabela;
DELETE: remove uma ou mais linhas de um banco de dados;
ALTER TABLE
ALTER TABLE played CHANGE played last_played TIMESTAMP;