0% found this document useful (0 votes)
14 views

Assi 2 DB

The document contains the SQL code to create tables for songs, singers, producers, studios, and albums with columns, primary keys, and foreign keys. It also includes SQL queries to insert sample data into the tables, select, update, delete and alter the tables.

Uploaded by

Aasma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assi 2 DB

The document contains the SQL code to create tables for songs, singers, producers, studios, and albums with columns, primary keys, and foreign keys. It also includes SQL queries to insert sample data into the tables, select, update, delete and alter the tables.

Uploaded by

Aasma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

____________________________________________________________________________________

1).

create table songs (


SongTitle VARCHAR(255),
year INT,
length INT,
album_id INT,
Singer_id INT,
PRIMARY KEY (SongTitle)
);

create table singers (


Sig_id INT,
name VARCHAR(255),
gender VARCHAR(1),
age INT,
rating INT,
Net_Earning DECIMAL(15, 2),
PRIMARY KEY (Sig_id)
);

CREATE TABLE Producer (


P_id INT,
name VARCHAR(255),
address VARCHAR(255),
startingYear INT,
PRIMARY KEY (P_id)
);

CREATE TABLE Studio (


studioName VARCHAR(255),
address VARCHAR(255),
OwnerName VARCHAR(255),
PRIMARY KEY (studioName)
);
CREATE TABLE Album (
Al_id INT ,
name VARCHAR(255),
production_amount DECIMAL(15, 2),
ProducerId INT,
Business_Amount DECIMAL(15, 2),
StudioName VARCHAR(255),
Singer_Id INT,
budget DECIMAL(15, 2),
PRIMARY KEY (Al_id),
FOREIGN KEY (ProducerId) REFERENCES Producer(P_id),
FOREIGN KEY (Singer_Id) REFERENCES Singers(Sig_id),
FOREIGN KEY (StudioName) REFERENCES Studio(studioName)
);

2).
INSERT INTO Songs (SongTitle, year, length, album_id, Singer_id) VALUES
('Bohemian Rhapsody', 1975, 354, 1, 1),
('Stairway to Heaven', 1971, 481, 2, 2),
('Smells Like Teen Spirit', 1991, 301, 3, 3),
('Imagine', 1971, 182, 4, 4),
('Like a Rolling Stone', 1965, 365, 5, 5);

INSERT INTO singers (Sig_id,name, gender, age, rating) VALUES


(1, 'Freddie Mercury', 'M', 45, 9),
(2, Robert Plant, 'M', 73, 7),
(3, 'Kurt Cobain', 'M', 27, 9),
(4, 'John Lennon', 'M', 40, 8),
(5, 'Bob Dylan', 'M', 80, 6);
INSERT INTO Producer (P_id,name, address, startingYear) VALUES
(1, 'George Martin', 'London', 1950),
(2, 'Rick Rubin', 'Los Angeles', 1980),
(3, 'Max Martin', 'Stockholm', 1990),
(4, 'Dr. Dre', 'Los Angeles', 1992),
(5, 'Quincy Jones', 'Los Angeles', 1950);

INSERT INTO Studio (studioName, address, OwnerName) VALUES


('Abbey Road Studios', 'London', 'EMI'),
('Electric Lady S', 'New York', 'Jimi Hendrix'),
('Paramount Recording Studios', 'Los Angeles', 'ABC'),
('Sunset Sound Recorders', 'Los Angeles', 'Salvador'),
('Capitol Studios', 'Los Angeles', 'EMI');

INSERT INTO Album (Al_id,name, production_amount, Business_Amount, budget) VALUES


(1, 'Thriller', 100000.0, 500000.0, 100000.0),
(2, 'Back in Black', 90000.0, 400000.0, 90000.0),
(3, 'The Dark Side of the Moon', 80000.0, 300000.0, 80000.0),
(4, 'Hotel California', 70000.0, 200000.0, 70000.0),
(5, 'Nevermind', 60000.0, 100000.0,60000.0);
3).
SELECT DISTINCT name
FROM Singers;

4).
SELECT name
FROM Producer
WHERE startingYear > 2000
AND P_id IN (
SELECT ProducerId
FROM Album
GROUP BY ProducerId
HAVING COUNT(*) >= 5
);

5).
select MAX(length)from songs;
select min(length) from songs;
6).
ALTER TABLE Songs ADD COLUMN rating FLOAT DEFAULT 0;

ALTER TABLE Singers ADD COLUMN Net_Earning FLOAT DEFAULT 0;

7).
ALTER TABLE producer DROP COLUMN gender;
8).
SELECT name
FROM Singers
WHERE Net_Earning > 500000 OR (Net_Earning >= 800000 AND Net_Earning <= 1200000);

9).
SELECT CONCAT(name, ' lives in ', address) AS `Producer's Details`
FROM Producer;

10).
SELECT Album.name, Album.production_amount, COUNT(Songs.SongTitle) AS TotalSongs,
SUM(Songs.length) AS TotalLength
FROM Album
JOIN Songs ON Album.Al_id = Songs.album_id
GROUP BY Album.name, Album.production_amount;
11).
SELECT name FROM Album WHERE StudioName = 'Music Studio Co.';

12).(a)
select* from singers
where length(name)>=3;

12).(b)
select* from singers
where name like '%a%';

12).(c)
select* from singers
where name like 's%a';

12).(d)
select* from singers
where name like '%d%'or name like'%b%';
Perform these queries.

12).(e)
select* from singers
where name not like '%g%';

13).
UPDATE Album SET budget = 40000
WHERE ProducerId = 6 AND name = 'Saher Ali Bagga';

14).
SELECT SongTitle FROM Songs
WHERE Singer_id IN (SELECT Sig_id FROM Singers WHERE name = 'Mary Moore')
AND length >= 3;

15).
DELETE FROM Studio
WHERE OwnerName = 'XXYYZZ';

I didn’t knew how to turn off safe update mode soo im just posting it like this
16).
UPDATE Album
SET budget = budget * 1.1
WHERE ProducerId = 12;

You might also like