Someone please help me Design the database of bill of materials with 1 item can have mutiple parent

I got this sample from  Uri
Dimant (MCC, MVP) ,
The problem is i want 1 item to have multiple parent  but this example don t   let 1  item to have multiple parents. this is not suit for my objective. 
CREATE TABLE Employees
  empid   int         NOT NULL,
  mgrid   int         NULL,
  empname varchar(25) NOT NULL,
  salary  money       NOT NULL,
  CONSTRAINT PK_Employees PRIMARY KEY(empid),
  CONSTRAINT FK_Employees_mgrid_empid
    FOREIGN KEY(mgrid)
    REFERENCES Employees(empid)
CREATE INDEX idx_nci_mgrid ON Employees(mgrid)
SET NOCOUNT ON
INSERT INTO Employees VALUES(1 , NULL, 'Nancy'   , $10000.00)
INSERT INTO Employees VALUES(2 , 1   , 'Andrew'  , $5000.00)
INSERT INTO Employees VALUES(3 , 1   , 'Janet'   , $5000.00)
INSERT INTO Employees VALUES(4 , 1   , 'Margaret', $5000.00) 
INSERT INTO Employees VALUES(5 , 2   , 'Steven'  , $2500.00)
INSERT INTO Employees VALUES(6 , 2   , 'Michael' , $2500.00)
INSERT INTO Employees VALUES(7 , 3   , 'Robert'  , $2500.00)
INSERT INTO Employees VALUES(8 , 3   , 'Laura'   , $2500.00)
INSERT INTO Employees VALUES(9 , 3   , 'Ann'     , $2500.00)
INSERT INTO Employees VALUES(10, 4   , 'Ina'     , $2500.00)
INSERT INTO Employees VALUES(11, 7   , 'David'   , $2000.00)
INSERT INTO Employees VALUES(12, 7   , 'Ron'     , $2000.00)
INSERT INTO Employees VALUES(13, 7   , 'Dan'     , $2000.00)
INSERT INTO Employees VALUES(14, 11  , 'James'   , $1500.00)
WITH EmpCTE(empid, empname, mgrid, lvl)
AS
  -- Anchor Member (AM)
  SELECT empid, empname, mgrid, 0
  FROM Employees
  WHERE empid = 1
  UNION ALL
  -- Recursive Member (RM)
  SELECT E.empid, E.empname, E.mgrid, M.lvl+1
  FROM Employees AS E
    JOIN EmpCTE AS M
      ON E.mgrid = M.empid
SELECT * FROM EmpCTE
My object is
I want to design the database of bill of materials which contain item and amount.
So the amount of child will depend on amount of parent in term of ratio. For example
A(1)               A(2)
|         ---->     |
B(2)               B(4)
My problem is when i try to add the parent and child . Let A is the parent of B , If i try to add A to be the child of C
I want B to come along with A as well. For example
A                       C
|     C  --->        |           For this I have to store the relation of all item in  my list to check that this item have a child or not if yes
B                            
A              The child must come along with its parent , What the Er-diagram should be for all of my requirement?
    |
    B
Base on the example that Uri
Dimant gave me ,  i have to stroe 1 item wtih multi parents for example if b is a child of a And b  have c as child , When i insert D as a parent of B   , c will automatic come along with B , But this not seem gonna work.
item   Parent 
 A      NULL
B         A
C         B
B         D
Am i wrong to go this way  , any idea

thanks Uri
Dimant
I am
little confuse about how can i write
hierarchy sql  from this relation  , Thanks
so far i got 
WITH EmpCTE(cid, cname, pid, lvl)
AS
  SELECT      cid , cname ,  children.pid , 0
  FROM            children INNER JOIN
  parents ON children.pid = parents.pid
  where  cid = 1
  UNION ALL
  SELECT      E.cid , E.cname ,  E.pid , M.lvl+1
  FROM       ( select  cid , cname , children.pid FROM  children INNER JOIN
  parents ON children.pid = parents.pid) AS E JOIN EmpCTE AS M
      ON E.pid = M.cid
SELECT * FROM EmpCTE  

Similar Messages

  • Someone please help me Design the database of bill of materials

    I want to design the database of bill of materials which contain item and amount.
    So the amount of child will depend on amount of parent in term of ratio. For example
    A(1)               A(2)
    |         ---->     |
    B(2)               B(4)
    My problem is when i try to add the parent and child . Let A is the parent of B , If i try to add A to be the child of C
    I want B to come along with A as well. For example
    A                       C
    |     C  --->        |           For this I have to store the relation of all item in  my list to check that this item have a child or not if yes
    B                             A              The child must come along with its parent , What the Er-diagram
    should be for all of my requirement?
                                    |
                                    B

    >I want B to come along with A as well. For example
    You can do that, but that is not automatic. You need to do some programming.
    It is better to use hierarchyid representation of the tree over traditional FK referencing.
    Tree using hierarchyid example:
    http://www.sqlusa.com/bestpractices2008/orgchart/
    BOL: "Model Your Data Hierarchies With SQL Server 2008
    .....The manufacturing system behind automobiles; the organization of a country into states, counties, cities, and postal codes; the description of a home entertainment system—what do these things have in common? The simple answer is that each
    describes a hierarchy.
    SQL Server 2008 supports a new data type, HierarchyID, that helps solve some of the problems in modeling and querying hier­archical information. I will introduce you to this data type by discussing a pattern commonly used in manufacturing
    known as bill of materials (BOM), or bills. Starting with a brief discussion of BOMs, I will illustrate how this kind of data can be modeled. I will also present an implementation of this model in SQL Server 2005. Then I will show you how the HierarchyID data
    type can be used to implement the model in SQL Server 2008.
    Hierarchical Data
    Automobiles are amalgamations of many components, such as engines, drivetrains, electronics, and steering. In the United States, our geographic territories are divided into states and are then sub-divided into jurisdictions called counties.
    Counties are then further subdivided in different ways by different agencies. The United States Census Bureau, for example, composes them from Census Tract Areas. The U.S. Postal Service routes mail delivery by Zone Improvement Plan (ZIP) codes. Geographic
    information systems (GIS) may aggregate census tracts and ZIP codes together to provide users with a familiar spatial reference for an area.
    A recent trip to a local electronics store to evaluate a replacement home entertainment system pointed to a similar sort of hierarchical system—all the combinations of possible components and options left my head spinning! I wondered
    how such systems could be modeled and implemented in a database system.
    The relationship between an automobile and its engine represents a hierarchy: the automobile contains the engine. The relationship is the same for the drivetrain, the electronics, and the steering. The relationship is containment. A
    similar hierarchy can be observed in the relationship between the different groupings of geographic or census data.
    Hierarchies exist everywhere, yet implementing them in the context of a relational database frequently proves to be a challenge. A typical approach is to represent the hierarchy using a parent/child relationship with one or more tables.
    While this approach certainly works in many cases, it has a few shortcomings. Such solutions must carefully consider how the referential integrity will be maintained. And while querying the depth and breadth of such tables was considerably simplified in SQL
    Server 2005 with the introduction of recursive common table expressions, writing queries against these types of tables can still be problematic when joins against many tables are required.
    A Bill of Materials Problem
    A few years ago I was working on a system being developed by a manufacturing company to help their dealers specify the components needed to build center-pivot irrigation systems. The software produced a list of components needed to custom-build
    the desired pivot (the totality of a center-pivot irrigation system is simply referred to as a pivot within the industry). The required components were determined based on geography, soil type, and the intended crops planted in the areas to be covered as well
    as the hydrologic and structural considerations of the device itself.
    Underpinning the solution would be a SQL Server database. The purpose of the database was to store information about the components available to build the pivot. However, when we generated the specification for manufacturing, we needed
    to identify those components as BOMs.
    Some bills represented a collection of physical parts that would be assembled into a system component. For example, every pivot needed a pump to draw water from a well into the system. That pump might be electrically powered, meaning
    it needed a transformer and fuse box, too. Or the pump might be fuel powered, meaning it needed a tank, a fuel pump, and hoses to connect the pump to the tank. In either case, the required parts for the pump would be listed in a pump bill.
    The bill for a complete pivot would include a collection of other bills. For example, a standardized pivot might consist of a tree of bills for the pump, another tree of bills for the spans of pipe used to deliver water, and bills for any other equipment
    needed to build that pivot system."
    LINK: http://msdn.microsoft.com/en-us/magazine/cc794278.aspx
    Kalman Toth Database & OLAP Architect
    SELECT Query Video Tutorial 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Someone please help me for the love of god!!!

    I currently have a MBP unibody 15" 2.53 I have all the cables etc etc, I am trying to hook this thing up to my Samsung 46" LCD. I have tried everything and I cannot get it to sync perfectly with my TV. What am I doing wrong? Can someone please tell me what setting my TV needs to be on and what setting my laptop needs to be on? I am dying over here spent close to $100 on cables and I cannot get this SOB to work.... Here are the specs on my TV if that helps at all.....
    http://www.amazon.com/Samsung-LN46B630-46-Inch-1080p-Touch/dp/B001U3Y8QI#moreAbo utThisProduct

    Hey Michael,
    I am using a Mini Display that plugs into the MBP and I am running an HDMI into that to the TV, I have a 24" LG monitor that I have had it hooked up to but I would like to have it hooked up to my TV. When I have it hooked up to the monitor in mirror mode and I close the laptop and hit the keyboard or mouse and it syncs with the monitor and adjusts to fit the screen perfectly. However, when I do that with my big screen it doesnt do that. It does show the Samsun in the Pref. Panel. and it is in Mirror Mode, I am not really sure what resolutions the Samsung preference shows.
    Is there something that I need to set on my TV to make it realize that I am hooking up a laptop to it? Also what setting would I need to put in display preferences? I am reallly really confused here. When I go to hook up my laptop all I do is plug in the cables go to system settings and click the highest resolution close the laptop and then reset it and it adjust to the correct resolution on my monitor, For some reason it doesnt seem to wanna do that when I have it hooked up to the TV.
    What would I want to do on the TV to make it so it adjusts?
    Thanks for all the help man I reallly appreciate this.

  • Can someone please help me get the close minamize and maximize buttons back above each video?

    I enterened something in terminal that made the top bar on each video with the close minamize and maximize buttons disapear...does anyone know how to get it back? thank you in advanced.

    Check the very first post on this forum:  http://forums.macrumors.com/showthread.php?t=775514.  You didn't mention whether your controller has disappeared also, but it seems like the second or fourth command on that page should help.

  • SOMEONE PLEASE HELP! I am desperate..."error with audio configuration"

    I have had a flurry of problems that are related in another link, about drives.
    I had to complete restore my library and import back each of my songs individually, which was successful. I also needed to install the new iTunes 7.7
    However, when I launched iTunes only about a minute later, a message popped up saying that "iTunes has detected a problem with your audio configuration. Audio/Video playback may not operate properly." And now, NONE of my songs or videos will play.
    PLEASE HELP! I've spent the past 2 days trying to fix a lot of things, and all of them seemed solved until this problem. I'm leaving in 7 HOURS! So please, help is appreciated.

    Go into your Control panel, and launch the "Sounds and Audio Devices" control panel. Click on the "Audio" tab.
    Is the correct default device showing up in the "Sound Playback" area?

  • Could someone please help me model the following circuit in Multisim?

    I have connected a BNC tee adapter to an oscilloscope. At one of the ends of the tee connector I have placed a 50 ohm terminator. At the other end of the tee I have placed a pulse generator with the following specs: a pulse amplitude of -0.8 V (for resistive loads of 50 ohms to 10 kilo ohms) that is 6-10 ns in duration with a 10 kHz repetition rate. The pulse generator also has a risetime of 1.5 ns and a fall time of 5 ns. Thank You    

    Hello,
    Here are some ideas to model this circuit. For the BNC terminator you could simply use a 50 ohm resistor; for the pulse generator I recommend you to take a look of the SIGNAL_VOLTAGE_SOURCES Family, Sources Group in the Multsim Master Database. The PULSE_VOLTAGE source could be an option since it allows you to configure many parameters (rise/fall time, pulse width, period, etc).
    Are you building a circuit to take a specific measurement (for instance: Time Domain Reflectrometry)?
    Hope this helps.
    Fernando D.
    National Instruments

  • TS2776 Can someone please help me im getting a Error message when syncing with iTunes "The iPhone "name"cannot be synced. A duplicate file name was specified"

    can some one help pleace!

    In the course of your troubleshooting to date, have you worked through the following document?
    iTunes: Troubleshooting issues with third-party iTunes plug-ins

  • Can someone please help me find the correct driver for my audio ca

    Hello, it's famke again...Still trying to find drivers.. My sound card is apparently also missing drivers... I've tried many drivers from different sites matching the information i've taken off the card...but for some reason i always get a big red slash through my audigy sound control panel after trying to install the driver and reboot my system... I'm convinced i haven't been able to find the correct driver... The information off the card is...Soundblaster Audigy 2ZS M:SB0350... If anyone can help out i would greatly appreciate this...Famke.

    I'm new to this, but I also had trouble for a while in finding and installing the right drivers. Eventually I got it to work with the link below. Follow the steps and select everything it suggests (I did and it worked for me). You might want to try it and see if it works for you too. Good Luck. http://www.creative.com/language.asp...wnloads/su.asp

  • Can someone please help a new owner of a Pixma Pro-100 with a color cast problem?

    Despite setting it up correctly with the drivers supplied on the CD for my Windows 7 64-bit laptop, I'm getting a slight pink color cast on both Canon's Fine Art Museum Etching and Glossy Plus II papers. It is neither a monitor calibration nor a software processing (white balance) issue, since I printed exactly the same file on my old Pixma IP4840 without any problem whatsoever. Unfortunately the IP4840 cannot handle the heavier grade media, nor print exhibition grade quality.
    I have tried adjusting the C, M, Y values according to the print pattern as recommended, without any significant improvement. I have used both the Pro and ICC profiles with similar lack of success.
    In desperation I downloaded the 32-bit driver to try on my Windows 8 desktop, also to no avail.
    I'm sincerely hoping there's a simple solution to what has thus far been a disappointing debut to the Pro series.
    Kindest regards,
    Richard 

    no, I didn't ask to burn a picture....this is why I am confused to how the picture got on there.
    I understand what you are saying regarding the multi-session thing (how do I avoid this if my other cds with photos on them have this, and I don't know they do?)
    but what I do know is that cd had photos on it (it definately wasn't full, and maybe that is why I haven't had a problem with others...they have all been full) and no one else uses my Mac, so I know no one else put the picture on that cd. I may have inadvertantly burned the picture, but if I did, I don't know what I did to make it burn the picture onto the cd.....
    The only thing that happened was I opened iphoto so I could save some of the pictures that were already on the disc, but when I went to look for the pictures on the cd, the only thing that was on it, was an iphoto picture....which I didn't ask to be put there.....
    I have previously burned pictures onto CD using my Mac with no problem, and I've pulled pictures off CD that were burned using a PC. So I guess I need to know how to determine if the cds have this multi-session thing going on?
    iMac Intel Core Duo   Mac OS X (10.4.7)  

  • How to watch live cricket matches in ipad.....should we download any apps....someone please help...

    How to watch live cricket matches in ipad.....should we download any apps....someone please help...

    The iPad does not use Flash so you will have to search for a TV app or an app that will stream the content that you want to watch. I have apps stream live content. WatchESPN and CNN are two apps that stream live content. You just have to start searching. Use a Google search for starters.

  • So i got this laptop today, and i'm trying to put my iPod music on it. i got the music but it only plays when my ipod is plugged into it. when i unplug my ipod, and try to play music, it says cannot play previous purchases... someone please help!!

    someone please help me!

    The ipod is not a backup device. The music sync is one way - computer to ipod.  The only exception is itunes purchases:  Without syncing:File>transfer Purchases
    Copy everything from your backup copy of your  old computer to your new one.

  • I have tried everything under the sun to turn my iphone4 on and nothing is working. Someone please help me!!!

    Nothing will turn my iphone on someone please help me.

    Holding the sleep/awake button down and the home button at the same time. Plugged it into my computer and my computer would not even recognize my phone

  • TS1717 I have uninstalled and restalled the latest itunes version and it still says that I need to reinstall it. Can someone please help me

    Recently I installed iTunes on my computer so that I could put music on my new iPad and it was fine, the next day when I went to put some more on it it asked me to download the newest version of iTunes and I did but since then I have been having trouble getting access to iTunes. I have uninstalled and reinstalled the latest itunes version and it still says that I need to reinstall it. Can someone please help me

    Hi l.johnson66,
    If you are having issues with iTunes after an attempted update, you may find the following article helpful:
    iTunes 11.1.4 for Windows: Unable to install or open
    http://support.apple.com/kb/TS5376
    Regards,
    - Brenden

  • Just update my mac it said "critical update" something like that so i updated and now my screen has like random dots all over and the colours are all messed up its like negative can someone please help?

    just update my mac it said "critical update" something like that so i updated and now my screen has like random dots all over and the colours are all messed up its like negative can someone please help?

    Adds the ability to make and receive FaceTime audio calls
    Adds call waiting support for FaceTime audio and video calls
    Adds the ability to block incoming iMessages from individual senders
    Improves the accuracy of unread counts in Mail
    Resolves an issue that prevented Mail from receiving new messages from certain providers
    Improves AutoFill compatibility in Safari
    Fixes an issue that may cause audio distortion on certain Macs
    Improves reliability when connecting to a file server using SMB2
    Fixes an issue that may cause VPN connections to disconnect
    Improves VoiceOver navigation in Mail and Finder
    Provides a fix for SSL connection verification
    this was the update
    never said anything about the screen

  • My screen won't work, i have tried turning it off but i cant swipe the power down button because my screen doesnt work. I have only had my iphone 4s for one day and this has happened, someone please help me.

    My screen won't work, i have tried turning it off but i cant swipe the power down button because my screen doesnt work. I have only had my iphone 4s for one day and this has happened, someone please help me.

    Did the trick!  Not sure what I did to cause the screen to go numb, but this worked perfectly!!!  I cleaned the screen and must have inadvertently selected something that locked the screen.  This perfect solution kept me from having to run to the Apple Store.  Many thanks.

Maybe you are looking for