Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Foreign Keys


Foreign Keys

Author
Message
Deepak Patil-309214
Deepak Patil-309214
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 1
 If you don’t have a key, you don’t have a table!     
- Joe Celko
It is very nice article 
which one can easly understand
without deep knowlege of MSSQL.
Also basic concepts are explained very well !!!!!
 
 

Roger Thomas
Roger Thomas
Grasshopper
Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)Grasshopper (14 reputation)

Group: General Forum Members
Points: 14 Visits: 8
Good, terse explanation.

The only issue I'd have with it is the use of the terminology "Parent" and "Child" to describe the relationship between the primary key and the foreign key(s) that reference it. In the best methodologies I've seen, the terms "parent" and "child" are reserved for unusual situations where you have things that depend for their existence on other things. An example of this might be a line on an invoice - the invoice must exist for the line to exist, do the invoice would be the "parent" and the line the "child". With dissimilar things, such as drivers and racecars, you'd have two distinct entities that were related by a foreign key, but neither would be the "parent" of the other.

That's terminology, but it avoids confusion.
Ian Yates
Ian Yates
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1056 Visits: 445

Fair comment from Roger. Makes me think actually that the next step for the article would be many-many relationship as many people get that confused





bitbucket-25253
bitbucket-25253
SSCertifiable
SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)SSCertifiable (5.7K reputation)

Group: General Forum Members
Points: 5689 Visits: 25280

As usual I am a day late and a dollar short, but heck was a good, clear, concise tutorial on foreign keys.

Thanks for the effort you put into this ... and as suggested by some one else, would be nice if you took the challenge and attempted to 'explain' the many to many relationship.

Again - thanks



If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Ravi Prashanth Lobo-275382
Ravi Prashanth Lobo-275382
Grasshopper
Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)Grasshopper (24 reputation)

Group: General Forum Members
Points: 24 Visits: 1

Thank you all for your suggestions!


Vic Kirkpatrick-173212
Vic Kirkpatrick-173212
Mr or Mrs. 500
Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)Mr or Mrs. 500 (501 reputation)

Group: General Forum Members
Points: 501 Visits: 76
To not use FKs in an OLTP with any level of complexity is just plain ignorant. There is no excuse for it, and you will just get badly burned. Amazingly enough, through my career I've had to fight developers, managers, and even other DBAs in order to install FKs on databases! It's incredible. In almost every case, they have grown to see the rewards by catching logic / data problems in testing with the FKs. Not to mention happy customers...
nogoodboyo
nogoodboyo
SSC Rookie
SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)SSC Rookie (36 reputation)

Group: General Forum Members
Points: 36 Visits: 352

No mention of trusted FK's? See http://sqlblog.com/blogs/hugo_kornelis/archive/2007/03/29/can-you-trust-your-constraints.aspx Handy to know, especially if you are lumbered with a db that exposes all data through very complex (and poorly performing )views!


balaji_rcs
balaji_rcs
SSC Rookie
SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)SSC Rookie (38 reputation)

Group: General Forum Members
Points: 38 Visits: 93
Hi,

This is really a good article. I had an doubt about that i want to generate the insert statement script for moving the data from one db to another. Nearly 500 tables are there, i want to know how to prioritize the tables list. Becuase each and every tables are internally referenced. Can you please help out to fix the issue
naveenreddy.84
naveenreddy.84
Valued Member
Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)Valued Member (56 reputation)

Group: General Forum Members
Points: 56 Visits: 287
Hi,

Can you help me out in updating such Foreign Key relationships. In one of my tables, i have a FK relationship refering to my primary key of the same table.

The Table called MacMaster has following columns:

MacID MacName ClusterID


the ClusterID here is a foreign key referencing the MacID(PK) of the same table.


MacID(identity column;PK) MacName ClusterID
1 Mac1 2
2 Mac2 NULL

I was trying to load this table from an another table having following column

MacName ClusterName
Mac3 Mac4
Mac4 NULL
Mac5 NULL

Kindly suggest me a method to load the above data to MacMaster Table.
Finally my MacMaster table should have something like this:

MacID MacName ClusterID
1 Mac1 2
2 Mac2 NULL
3 Mac3 4
4 Mac4 NULL
5 Mac5 NULL

Is this can be achieved through TSql or do i need to create a some kind of front end for it.Kindly Suggest

Regards,
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search