-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMusicDB-Server.sql
67 lines (60 loc) · 2.66 KB
/
MusicDB-Server.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
-- create db Music
use master;
go
drop database if exists Music;
go
create database Music;
go
use Music;
go
Create table artist
(
ID int primary key identity(1,1),
name varchar(100) not null,
genre varchar(100) not null
)
Create table Album
(
ID int primary key identity(1,1),
Title varchar(100) not null,
artistID int Foreign key references artist(ID) not null
)
Create table Song
(
ID int primary key identity(1,1),
name varchar(100) not null,
aristID int Foreign key references artist(ID) not null,
albumID int Foreign key references album(id) not null
)
Insert artist
(name, genre)
VALUES
('Taylor Swift', 'Country/Pop'),
('Kid Cudi', 'Rap');
insert Album
(Title, artistID)
VALUES
('Fearless', (select ID from artist where name like '%Taylor Swift%')),
('Folklore', (select ID from artist where name like '%Taylor Swift%')),
('Man on the Moon: The End of Day', (select ID from artist where name like '%Kid Cudi%')),
('Man on the Moon 2: The Legend of Mr Rager', (select ID from artist where name like '%Kid Cudi%'));
insert Song
(name, aristID, albumID)
VALUES
('Fearless', (select ID from artist where name like '%Taylor Swift%'), (select ID from Album where title like '%Fearless%')),
('Love Story', (select ID from artist where name like '%Taylor Swift%'), (select ID from Album where title like '%Fearless%')),
('Cardigan', (select ID from artist where name like '%Taylor Swift%'), (select ID from Album where title like '%Folklore%')),
('Seven', (select ID from artist where name like '%Taylor Swift%'), (select ID from Album where title like '%Folklore%')),
('Soundtrack 2 My Life', (select ID from artist where name like '%Kid Cudi%'), (select ID from Album where title like '%Man on the Moon: The End%')),
('Day ''n'' Nite (Nightmare)', (select ID from artist where name like '%Kid Cudi%'), (select ID from Album where title like '%Man on the Moon: The End%')),
('Pursuit of Happiness', (select ID from artist where name like '%Kid Cudi%'), (select ID from Album where title like '%Man on the Moon: The End%')),
('Mr. Rager', (select ID from artist where name like '%Kid Cudi%'), (select ID from Album where title like '%Man on the Moon 2: The Legend of%')),
('Mojo So Dope', (select ID from artist where name like '%Kid Cudi%'), (select ID from Album where title like '%Man on the Moon 2: The Legend of%'));
select s.ID as 'Song ID', s.name as 'Song Name', s.aristID as 'Songs Artist ID', s.albumID as 'Songs album ID',
al.ID as 'Album ID', al.Title as 'Album Name', al.artistID as 'Albums artist',
ar.ID as 'Artist ID', ar.name as 'Artist Name', ar.genre as 'Artist Genre'
from Song s
join Album al
on s.albumID = al.ID
join artist ar
on s.aristID = ar.ID;