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:
Authorsstores information about authors.Genresis a list of genres.Bookslinks a book with an author and genre, and contains the price and publication date.
This separation allows for easy data expansion and maintains integrity.