Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:04:03+00:00 2026-06-18T12:04:03+00:00

I’m trying to construct a database, but I’m fairly clueless about MySql. The following

  • 0

I’m trying to construct a database, but I’m fairly clueless about MySql. The following is what I’m aiming at achieving:
http://snag.gy/eryLf.jpg

Here’s what I coded so far (tables are created in left to right order as seen in the picture)

    CREATE TABLE person (
  id INT(11) PRIMARY KEY AUTO_INCREMENT,
  fname VARCHAR(64),
  lname VARCHAR(64)
) ENGINE = InnoDB;

CREATE TABLE bookauthor (
  book_id INT(11),
  author_id INT(11),
  FOREIGN KEY (author_id) REFERENCES person (id) ON UPDATE CASCADE,
  FOREIGN KEY (book_id) REFERENCES book (id) ON UPDATE CASCADE
) ENGINE = InnoDB;

CREATE TABLE bookpublisher (
  book_id INT(11),
  publisher_id INT(11),
  FOREIGN KEY (book_id) REFERENCES book (id) ON UPDATE CASCADE,
  FOREIGN KEY (publisher_id) REFERENCES publisher(id) ON UPDATE CASCADE
) ENGINE = InnoDB;

CREATE TABLE publisher (
  id INT(11) PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(64)
) ENGINE = InnoDB;

CREATE TABLE bookillustrator (
  book_id INT(11),
  illustrator_id INT(11),
  FOREIGN KEY (book_id) REFERENCES book(id) ON UPDATE CASCADE,
  FOREIGN KEY (illustrator_id) REFERENCES person(id) ON UPDATE CASCADE
) ENGINE = InnoDB;

CREATE TABLE book (
  id INT(11) PRIMARY KEY AUTO_INCREMENT,
  title VARCHAR(256),
  type_id INT(11),
  publication_date DATE,
  value DECIMAL(10,2),
  price DECIMAL(10,2),
  notes TEXT,
  signed TINYINT(1),
  grade_id INT(10),
  bagged TINYINT(1)
) ENGINE = InnoDB;

CREATE TABLE booktag (
  book_id INT(11),
  tag_id INT(11),
  FOREIGN KEY (book_id) REFERENCES book(id) ON UPDATE CASCADE,
  FOREIGN KEY(tag_id) REFERENCES tag(id) ON UPDATE CASCADE
) ENGINE = InnoDB;

CREATE TABLE tag (
  id INT(11) PRIMARY KEY AUTO_INCREMENT,
  value VARCHAR(64)
) ENGINE = InnoDB;

CREATE TABLE type (
  id INT(11) PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(64)
) ENGINE = InnoDB;

CREATE TABLE grade (
  id INT(11) AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(256)
) ENGINE = InnoDB;

Also what kind of relationship is displayed in book to type, and book to grade?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:04:05+00:00Added an answer on June 18, 2026 at 12:04 pm

    The book->type and book->grade relationships are 1:n where type and grade are optional. This is easily created with MySQL Workbench.

    This should do it:

    -- -----------------------------------------------------
    -- Table `type`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `type` (
      `id` INT(10) NOT NULL ,
      `name` VARCHAR(256) NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `grade`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `grade` (
      `id` INT(10) NOT NULL ,
      `name` VARCHAR(256) NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `book`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `book` (
      `id` INT(10) NOT NULL ,
      `title` VARCHAR(256) NOT NULL ,
      `type_id` INT(10) NULL ,
      `publication_date` DATE NULL ,
      `value` DECIMAL(10,2) NULL ,
      `price` DECIMAL(10,2) NULL ,
      `notes` TEXT NULL ,
      `signed` TINYINT(1) NULL ,
      `grade_id` INT(10) NULL ,
      `bagged` TINYINT(1) NULL ,
      PRIMARY KEY (`id`) ,
      INDEX `fk_book_grade` (`grade_id` ASC) ,
      INDEX `fk_book_type1` (`type_id` ASC) ,
      CONSTRAINT `fk_book_grade`
        FOREIGN KEY (`grade_id` )
        REFERENCES `grade` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `fk_book_type1`
        FOREIGN KEY (`type_id` )
        REFERENCES `type` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `tag`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `tag` (
      `id` INT(10) NOT NULL ,
      `value` VARCHAR(64) NOT NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `booktag`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `booktag` (
      `book_id` INT(10) NOT NULL ,
      `tag_id` INT(10) NOT NULL ,
      INDEX `fk_booktag_book1` (`book_id` ASC) ,
      INDEX `fk_booktag_tag1` (`tag_id` ASC) ,
      PRIMARY KEY (`book_id`, `tag_id`) ,
      CONSTRAINT `fk_booktag_book1`
        FOREIGN KEY (`book_id` )
        REFERENCES `book` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `fk_booktag_tag1`
        FOREIGN KEY (`tag_id` )
        REFERENCES `tag` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `person`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `person` (
      `id` INT(10) NOT NULL ,
      `fname` VARCHAR(64) NOT NULL ,
      `lname` VARCHAR(64) NOT NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `bookillustrator`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `bookillustrator` (
      `book_id` INT(10) NOT NULL ,
      `person_id` INT(10) NOT NULL ,
      INDEX `fk_bookillustrator_person1` (`person_id` ASC) ,
      INDEX `fk_bookillustrator_book1` (`book_id` ASC) ,
      PRIMARY KEY (`book_id`, `person_id`) ,
      CONSTRAINT `fk_bookillustrator_person1`
        FOREIGN KEY (`person_id` )
        REFERENCES `person` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `fk_bookillustrator_book1`
        FOREIGN KEY (`book_id` )
        REFERENCES `book` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `bookauthor`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `bookauthor` (
      `book_id` INT(10) NOT NULL ,
      `person_id` INT(10) NOT NULL ,
      INDEX `fk_bookauthor_person1` (`person_id` ASC) ,
      INDEX `fk_bookauthor_book1` (`book_id` ASC) ,
      PRIMARY KEY (`book_id`, `person_id`) ,
      CONSTRAINT `fk_bookauthor_person1`
        FOREIGN KEY (`person_id` )
        REFERENCES `person` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `fk_bookauthor_book1`
        FOREIGN KEY (`book_id` )
        REFERENCES `book` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `publisher`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `publisher` (
      `id` INT(10) NOT NULL ,
      `name` VARCHAR(64) NOT NULL ,
      PRIMARY KEY (`id`) )
    ENGINE = InnoDB;
    
    
    -- -----------------------------------------------------
    -- Table `bookpublisher`
    -- -----------------------------------------------------
    CREATE  TABLE IF NOT EXISTS `bookpublisher` (
      `book_id` INT(10) NOT NULL ,
      `publisher_id` INT(10) NOT NULL ,
      INDEX `fk_bookpublisher_book1` (`book_id` ASC) ,
      INDEX `fk_bookpublisher_publisher1` (`publisher_id` ASC) ,
      PRIMARY KEY (`book_id`, `publisher_id`) ,
      CONSTRAINT `fk_bookpublisher_book1`
        FOREIGN KEY (`book_id` )
        REFERENCES `book` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION,
      CONSTRAINT `fk_bookpublisher_publisher1`
        FOREIGN KEY (`publisher_id` )
        REFERENCES `publisher` (`id` )
        ON DELETE NO ACTION
        ON UPDATE NO ACTION)
    ENGINE = InnoDB;
    

    SQL Fiddle

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I want to construct a data frame in an Rcpp function, but when I
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.