美文网首页
SQL反模式-范例数据库

SQL反模式-范例数据库

作者: 富贵山庄王动 | 来源:发表于2017-03-16 22:59 被阅读0次
    CREATE TABLE Accounts (
      account_id SERIAL PRIMARY KEY ,
      account_name VARCHAR(20),
      first_name VARCHAR(20),
      last_name VARCHAR(20),
      email VARCHAR(100),
      password_hash CHAR(64),
      portrait_image BLOB,
      hourly_rate NUMERIC(9,2)
    );
    CREATE TABLE BugStatus (
      status VARCHAR(20) PRIMARY KEY
    );
    
    CREATE TABLE Bugs (
      bug_id SERIAL PRIMARY KEY ,
      date_reported DATE NOT NULL ,
      summary VARCHAR(80),
      description VARCHAR(1000),
      resolution VARCHAR(1000),
      reported_by BIGINT UNSIGNED NOT NULL ,
      assigned_to BIGINT UNSIGNED,
      verifyed_by BIGINT UNSIGNED,
      status VARCHAR(20) NOT NULL DEFAULT 'NEW',
      priority VARCHAR(20),
      hours NUMERIC(9,2),
      FOREIGN KEY (reported_by) REFERENCES Accounts(account_id),
      FOREIGN KEY (assigned_to) REFERENCES Accounts(account_id),
      FOREIGN KEY (verifyed_by) REFERENCES Accounts(account_id)
    );
    
    CREATE TABLE `Comments` (
      comment_id SERIAL PRIMARY KEY ,
      bug_id BIGINT UNSIGNED NOT NULL ,
      author BIGINT UNSIGNED NOT NULL ,
      comment_date DATETIME NOT NULL ,
      comment TEXT NOT NULL ,
      FOREIGN KEY (bug_id) REFERENCES Bugs(bug_id),
      FOREIGN KEY (author) REFERENCES Accounts(account_id)
    );
    
    CREATE TABLE Screenshots (
      bug_id BIGINT UNSIGNED NOT NULL ,
      image_id BIGINT UNSIGNED NOT NULL ,
      screenshot_image BLOB,
      caption VARCHAR(100),
      PRIMARY KEY (bug_id,image_id),
      FOREIGN KEY (bug_id) REFERENCES Bugs(bug_id)
    );
    
    CREATE TABLE Tags (
      bug_id BIGINT UNSIGNED NOT NULL ,
      tag VARCHAR(20) NOT NULL ,
      PRIMARY KEY (bug_id,tag),
      FOREIGN KEY (bug_id) REFERENCES Bugs(bug_id)
    );
    
    CREATE TABLE Products (
      product_id SERIAL PRIMARY KEY ,
      product_name VARCHAR(50)
    );
    
    CREATE TABLE BugsProducts (
      bug_id BIGINT UNSIGNED NOT NULL ,
      product_id BIGINT UNSIGNED NOT NULL ,
      PRIMARY KEY (bug_id,product_id),
      FOREIGN KEY (bug_id) REFERENCES Bugs(bug_id),
      FOREIGN KEY (product_id) REFERENCES Products(product_id)
    );
    CREATE TABLE Contacts (
      product_id BIGINT UNSIGNED NOT NULL,
      account_id BIGINT UNSIGNED NOT NULL ,
      PRIMARY KEY (product_id,account_id),
      FOREIGN KEY (product_id) REFERENCES Products(product_id),
      FOREIGN KEY (account_id) REFERENCES Accounts(account_id)
    );
    

    相关文章

      网友评论

          本文标题:SQL反模式-范例数据库

          本文链接:https://www.haomeiwen.com/subject/uwssnttx.html