Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 数据库设计&x2B;产品的两种类型的关系_Mysql_Sql_Database Design_Data Structures_Computer Science - Fatal编程技术网

Mysql 数据库设计&x2B;产品的两种类型的关系

Mysql 数据库设计&x2B;产品的两种类型的关系,mysql,sql,database-design,data-structures,computer-science,Mysql,Sql,Database Design,Data Structures,Computer Science,我需要一些关于数据库结构的帮助,我有三个表-一个是产品,用于基本产品信息;第二个是产品变体这与产品有关,产品变体可以是CD,DVD或蓝光,因此基本上它们是特定产品的产品类型-例如,矩阵是一种可以包含CD原声带、DVD和/或蓝光的产品 下一个我有问题的表格是特定产品类型的类型列表,我有属于某个产品的类型,例如动作、戏剧、科幻。。。但对于音轨或只是音乐CD,我会有不同的风格,如摇滚、爵士乐、流行音乐等。。。目前,我可以输出DVD和蓝光的所有类型,但我只想将这些特定类型显示给可能是CD类型、DVD类型

我需要一些关于数据库结构的帮助,我有三个表-一个是产品,用于基本产品信息;第二个是产品变体这与产品有关,产品变体可以是CD,DVD或蓝光,因此基本上它们是特定产品的产品类型-例如,矩阵是一种可以包含CD原声带、DVD和/或蓝光的产品

下一个我有问题的表格是特定产品类型的类型列表,我有属于某个产品的类型,例如动作、戏剧、科幻。。。但对于音轨或只是音乐CD,我会有不同的风格,如摇滚、爵士乐、流行音乐等。。。目前,我可以输出DVD和蓝光的所有类型,但我只想将这些特定类型显示给可能是CD类型、DVD类型或蓝光类型的特定产品

我的表格信息是这样的

产品::

Schema::create('products', function(Blueprint $table)
{
    $table->bigIncrements('id')->unsigned();
    $table->string('keywords');
    $table->string('title', 160);
    $table->text('description');
    $table->string('slug', 160);            
    $table->date('release_date');                       
    $table->string('clip', 160)->nullable();                        
    $table->timestamps();
});
产品种类:

Schema::create('productvariations', function(Blueprint $table)
{
    $table->bigIncrements('id')->unsigned();
    $table->bigInteger('product_id');                                           
    $table->string("image", 160)->nullable();
    $table->bigInteger('producttype_id')->unsigned();
    $table->decimal("price", 5, 2);
    $table->integer('quantity')->unsigned();
    $table->integer('discount')->default(0)->unsigned();
    $table->date("sale_start")->nullable();
    $table->date("sale_end")->nullable();
    $table->timestamps();
});
ProductTypse::

Schema::create('producttypes', function(Blueprint $table)
{
    $table->bigIncrements('id')->unsigned();
    $table->string('slug', 160);
    $table->string('title', 160);
    $table->string('keywords', 160);
    $table->string('description', 160);         
    $table->timestamps();
});
类型::

Schema::create('genretypes', function(Blueprint $table)
{

    $table->bigIncrements('id')->unsigned();            
    $table->string('slug', 160);
    [**$table->enum('type', array('Music', 'Movies')) Not sure about this approach**];
    $table->string('title', 160);           
    $table->timestamps();
});
Product_GenereType::[产品和类型的重要查找表联接表]

Schema::create('product_genretypes', function(Blueprint $table)
{
    $table->bigInteger('product_id')->unsigned();           
    $table->bigInteger('genretype_id')->unsigned();
    $table->unique( array('product_id','genretype_id') );                               
    $table->timestamps();
});

看起来您还需要一个producttypes\u genretypes x-ref表,以便指定与哪个产品类型相关的类型。你可以从产品和类型类型到产品类型进行复杂的连接,以获得关系,但如果任何产品类型中没有产品,这可能会遗漏一些。我只是想在产品类型中增加一个名为genretype(电影、音乐)的字段然后在我的genretypes表中,我可以添加另一个名为genretype的字段,这是一个电影的枚举,音乐可以帮助建立这种关系