Untitled

 avatar
unknown
plain_text
14 days ago
1.4 kB
2
Indexable
CREATE TABLE tbl_artists (
    artist_id INT AUTO_INCREMENT PRIMARY KEY,
    artist_name VARCHAR(100)
);


CREATE TABLE tbl_albums (
    album_id INT AUTO_INCREMENT PRIMARY KEY,
    album_title VARCHAR(100),
    artist_id INT,
    release_year INT,
    FOREIGN KEY (artist_id) REFERENCES tbl_artists(artist_id)
);

CREATE TABLE tbl_songs (
    song_id INT AUTO_INCREMENT primary KEY,
    song_title VARCHAR(200),
    duration INT,
    album_id INT,
    genre VARCHAR(50)
);

ALTER TABLE tbl_songs
add FOREIGN key (album_id) REFERENCES tbl_albums(album_id);

ALter table tbl_songs
modify column duration TIME;

ALter table tbl_artists
drop column artist_name;

alter table tbl_artists
add COLUMN artist_name varchar(100);

ALTER TABLE songs  
ADD COLUMN release_year INT;

INSERT INTO tbl_artists (artist_name)
VALUES 
('Sabrina Carpenter'),
('Taylor Swift'),
('Ariana Grande');

INSERT INTO tbl_albums (album_title, artist_id, release_year)
VALUES 
('Emails I Can’t Send', 1, 2022),
('1989', 2, 2014),
('Dangerous Woman', 3, 2016);

INSERT INTO tbl_songs (song_title, duration, album_id, genre)
VALUES 
('Nonsense', '02:40', 1, 'Pop'),
('Blank Space', '03:51', 2, 'Pop'),
('Into You', '04:04', 3, 'Pop');

SELECT * FROM songs  
ORDER BY song_title DESC;

SELECT DISTINCT genre FROM songs  
ORDER BY genre;

DELETE FROM songs WHERE song_id = 3;


Leave a Comment