Return how many artists are currently in the band, how many artists have ever been in the band (be careful not to count the same artists multiple times if they've left and rejoined) and the number of albums the band has made. (This is tricky! There are a number of ways you can approach this. Order by band from A-Z. Attached are tables and their values.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Return how many artists are currently in the band, how many artists have ever been in the band (be careful not to count the same artists multiple times if they've left and rejoined) and the number of albums the band has made. (This is tricky! There are a number of ways you can approach this.

Order by band from A-Z.

Attached are tables and their values.

```sql
/* Create all tables. Order matters due to foreign keys. */

CREATE TABLE p_artist (
    id INT AUTO_INCREMENT,
    fname VARCHAR(30) NOT NULL,
    lname VARCHAR(30),
    dob DATE,
    hometown VARCHAR(40),
    gender CHAR(1),
    PRIMARY KEY (id)
) ENGINE = innodb;

CREATE TABLE p_band (
    id INT AUTO_INCREMENT,
    title VARCHAR(50) NOT NULL,
    year_formed YEAR,
    PRIMARY KEY (id)
) ENGINE = innodb;

CREATE TABLE p_member (
    artist_id INT NOT NULL,
    band_id INT NOT NULL,
    joined_date DATE,
    leave_date DATE,
    FOREIGN KEY (artist_id) REFERENCES p_artist(id),
    FOREIGN KEY (band_id) REFERENCES p_band(id)
) ENGINE = innodb;

CREATE TABLE p_album (
    id INT not null,
    pub_year YEAR,
    title VARCHAR(50),
    publisher VARCHAR(50),
    format CHAR(1),
    band_id INT NOT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (band_id) REFERENCES p_band(id)
) ENGINE = innodb;

CREATE TABLE p_song (
    album_id INT NOT NULL,
    name VARCHAR(30) NOT NULL,
    length TIME,
    FOREIGN KEY (album_id) REFERENCES p_album(id)
) ENGINE = innodb;
```

### Explanation:

This SQL script creates a database schema for managing musical information. It includes tables for artists, bands, members, albums, and songs. 

1. **p_artist Table**: Stores details about artists, including first name, last name, date of birth, hometown, and gender. Each artist has a unique ID as the primary key.

2. **p_band Table**: Holds information about musical bands, such as the title (name) and the year the band was formed. Each band is also uniquely identified by an ID.

3. **p_member Table**: Establishes a relationship between artists and bands. It records when an artist joined or left a band using `artist_id` and `band_id` as foreign keys that reference the `p_artist` and `p_band` tables, respectively.

4. **p_album Table**: Contains details about albums, including publication year, title, publisher, format, and the associated band. Each album requires a unique ID, and the `band_id` serves as a foreign key referencing a band.

5. **p_song Table**
Transcribed Image Text:```sql /* Create all tables. Order matters due to foreign keys. */ CREATE TABLE p_artist ( id INT AUTO_INCREMENT, fname VARCHAR(30) NOT NULL, lname VARCHAR(30), dob DATE, hometown VARCHAR(40), gender CHAR(1), PRIMARY KEY (id) ) ENGINE = innodb; CREATE TABLE p_band ( id INT AUTO_INCREMENT, title VARCHAR(50) NOT NULL, year_formed YEAR, PRIMARY KEY (id) ) ENGINE = innodb; CREATE TABLE p_member ( artist_id INT NOT NULL, band_id INT NOT NULL, joined_date DATE, leave_date DATE, FOREIGN KEY (artist_id) REFERENCES p_artist(id), FOREIGN KEY (band_id) REFERENCES p_band(id) ) ENGINE = innodb; CREATE TABLE p_album ( id INT not null, pub_year YEAR, title VARCHAR(50), publisher VARCHAR(50), format CHAR(1), band_id INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (band_id) REFERENCES p_band(id) ) ENGINE = innodb; CREATE TABLE p_song ( album_id INT NOT NULL, name VARCHAR(30) NOT NULL, length TIME, FOREIGN KEY (album_id) REFERENCES p_album(id) ) ENGINE = innodb; ``` ### Explanation: This SQL script creates a database schema for managing musical information. It includes tables for artists, bands, members, albums, and songs. 1. **p_artist Table**: Stores details about artists, including first name, last name, date of birth, hometown, and gender. Each artist has a unique ID as the primary key. 2. **p_band Table**: Holds information about musical bands, such as the title (name) and the year the band was formed. Each band is also uniquely identified by an ID. 3. **p_member Table**: Establishes a relationship between artists and bands. It records when an artist joined or left a band using `artist_id` and `band_id` as foreign keys that reference the `p_artist` and `p_band` tables, respectively. 4. **p_album Table**: Contains details about albums, including publication year, title, publisher, format, and the associated band. Each album requires a unique ID, and the `band_id` serves as a foreign key referencing a band. 5. **p_song Table**
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Table
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education