Sobes.tech
Middle

Write the physical database tables for a catalog service (books, authors, genres, price).

sobes.tech AI

Answer from AI

For a catalog service with books, authors, genres, and prices, the following physical tables can be designed:

-- Authors table
CREATE TABLE Authors (
    AuthorID INT PRIMARY KEY AUTO_INCREMENT,
    Name VARCHAR(255) NOT NULL,
    BirthDate DATE,
    Biography TEXT
);

-- Genres table
CREATE TABLE Genres (
    GenreID INT PRIMARY KEY AUTO_INCREMENT,
    Name VARCHAR(100) NOT NULL
);

-- Books table
CREATE TABLE Books (
    BookID INT PRIMARY KEY AUTO_INCREMENT,
    Title VARCHAR(255) NOT NULL,
    AuthorID INT NOT NULL,
    GenreID INT NOT NULL,
    Price DECIMAL(10, 2) NOT NULL,
    PublishDate DATE,
    FOREIGN KEY (AuthorID) REFERENCES Authors(AuthorID),
    FOREIGN KEY (GenreID) REFERENCES Genres(GenreID)
);

Here:

  • Authors stores information about authors.
  • Genres is a list of genres.
  • Books links a book with an author and genre, and contains the price and publication date.

This separation allows for easy data expansion and maintains integrity.

Write the physical database tables for a catalog… - sobes.tech