Solved

defining tables relationship

Posted on 2012-04-04
2
204 Views
Last Modified: 2012-06-21
Hello,

I need to relate 3 tables e.g. prod, series, sub-series and noticed that when I am using composite primary key it cannot be incremental. This is my plan and I will appreciate it if you give me some help:

table 1: prod     has prod_id (PK) and desc
table 2: series   has prod_id(FK and PK) and series_id (PK)
tables 3: sub-series  series_id (FK and PK) and sub_series(PK)

if this is a right approach, how can I make prod_id and series_id incremental ? and same thing about sub_series table?

if not, then what you suggest?

Thanks in advance,
ak
0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
lludden earned 200 total points
ID: 37807347
CREATE TABLE Prod (ProdKey INT IDENTITY(1,1) --Other fields)
CREATE TABLE Series (SeriesID INT IDENTITY(1,1), ProdKey int) --ProdKey is a FK to Prod Table
CREATE TABLE SubSeries(SubSeriesID int IDENTITY(1,1), SeriesID int) SeriesID is FK to Series table

Each Prod can have multiple series, but each series can only have 1 prod
Each Series can have multiple subSeries, but each sub-series can only belong to a single series.

If you want to allow multiple series to have multiple products (a many-to-many relationship), then you do it this way:
CREATE TABLE Prod (ProdKey INT IDENTITY(1,1) --Other fields)
CREATE TABLE Series (SeriesID INT IDENTITY(1,1) --Other fields)
CREATE TABLE ProductSeries( ProdKey int, SeriesID int) --Both Prodkey and seriesID make a composite PK

and to do the same with subseries
CREATE TABLE SubSeries(SubSeriesID int IDENTITY(1,1) --Other fields)
CREATE TABLE SeriesSubSeries(SeriesID int, SubSeriesID int) --Both seriesID and SubseriesID make a composite PK
0
 

Author Closing Comment

by:akohan
ID: 37825698
Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question