October 23, 2013 at 1:46 am
i have a table Line and this two table(Ramp and PreRamp) have relationship(one to many) to line table(there is no relation ship between ramp and PreRamp. how can i create relation ship between them.
Line:LineID,PointA,PointB
Ramp:RampID,InternalAx,InternalAy
PreRamp:PreRampID,Height,Slope
October 23, 2013 at 3:18 am
Your question isn't entirely clear, but I guess you can create a foreign key relationship.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 23, 2013 at 3:50 am
how can i create a table that have two foreign key.i mean my Line Table have relationship with two table(Ramp and PreRamp).this is the point that i get confused!!!
October 23, 2013 at 3:53 am
What are the relationships by the way?
Which columns are related to each other?
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 23, 2013 at 4:02 am
tables(Ramp and PreRamp)have one(Line Table) to many(Ramp and PreRamp Table) relationship with Line Table and i dont Know how can i do that.because there is RampID and PreRampID which one i use in Line Table because Line Table Have Relationship with Both of them.or can u say me how can i create table that have relationship(one to many) with two table??
October 23, 2013 at 4:42 am
In your table structure for Line you gave in your original post you specified LineID,PointA,PointB.
I don't see any RampID or PreRampID.
Please read the first link in my signature on how to post questions.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 23, 2013 at 8:21 am
vahid.arr (10/23/2013)
i have a table Line and this two table(Ramp and PreRamp) have relationship(one to many) to line table(there is no relation ship between ramp and PreRamp. how can i create relation ship between them.Line:LineID,PointA,PointB
Ramp:RampID,InternalAx,InternalAy
PreRamp:PreRampID,Height,Slope
Spend some here http://technet.microsoft.com/en-us/library/ms175464(v=sql.105).aspx
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
October 24, 2013 at 6:47 am
Koen Verbeeck (10/23/2013)
In your table structure for Line you gave in your original post you specified LineID,PointA,PointB.I don't see any RampID or PreRampID.
Please read the first link in my signature on how to post questions.
i know that.i don know how create relation between them.for example i put ForeignID(ID of RampID or PreRampID) and TableName(Ramp or PreRamp Table) in Line and or i put foregin key RampID and PreRampID separately in Line table
October 25, 2013 at 1:16 am
Try posting the actual table DDL and some sample data, it will make the problem more clear for others.
Read the first link in my signature on how to do this.
Need an answer? No, you need a question
My blog at https://sqlkover.com.
MCSE Business Intelligence - Microsoft Data Platform MVP
October 25, 2013 at 6:09 am
vahid.arr (10/24/2013)
i know that.i don know how create relation between them.for example i put ForeignID(ID of RampID or PreRampID) and TableName(Ramp or PreRamp Table) in Line and or i put foregin key RampID and PreRampID separately in Line table
(My coffee hasn't kicked in yet, so if I get this backwards, somebody correct me)
The table on the "many" side of a one-to-many relationship has a field to hold copies of the Primary Keys of the table on the "one" side of the relationship (or multiple fields if the other table has a composite primary key). Then you add a foreign key constraint to the "many" table referencing the primary key of the "one" table. Koen's link has the syntax.
The table names of the foreign key relationship don't go in fields in your tables, the table name is part of the CONSTRAINT syntax.
Tables can have multiple foreign key fields. Such tables are legion in Kimball-style data warehouses.
____________
Just my $0.02 from over here in the cheap seats of the peanut gallery - please adjust for inflation and/or your local currency.
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply