Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 11th, 2011, 01:37 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Where are my foreign keys?

Hi All,

I was reading an article about a certain bug in SQL 2005 that included a couple of queries to identify some problems with Foreign Keys. The results of the queries showed that I only have five Foreign Keys in my DB and I know there's a lot more than that.

Code:
select f.name
     , i.name
     , object_name(i.object_id) as tablename
     , i.is_unique,i.is_primary_key
     , i.type_desc
     , f.key_index_id 
 from sys.foreign_keys f 
   join sys.indexes i 
     on i.object_id = f.referenced_object_id 
     and i.index_id = f.key_index_id
     
     SELECT * FROM sys.foreign_keys
Obviously I'm not understanding something here. Why am I only showing five results when I run these queries on the Master DB?

Thanks in advance for your help.

Richard
 
Old October 11th, 2011, 05:01 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Do both queries return 5 records? When I run this on some database, both return the same number of records (189 to be exact).

How many foreign keys do you expect? Are you sure that 5 is not the right answer?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old October 11th, 2011, 06:32 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Imar,

Thanks for your reply. I'm sorry... I think my post was lacking.

I am running these queries on Microsoft SQL Server 2008 (SP2) - 10.0.4064.0 (X64) Feb 25 2011 13:56:11 Copyright (c) 1988-2008 Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2)

and not on SQL 2005.

Here is the article that I was checking out and where I got the queries.

http://www.sqlservercentral.com/arti...28FK%29/75346/

Damn database gremlins.

Now when I run the query on the Master I get no results and 156 on the DB where the tables exist and where I expect to see the Foreign Keys. I swear I ran that on the Master and kept switching back and forth.

Anyway... thank you Imar. Very much appreciate your reply.

Richard
 
Old December 14th, 2011, 07:03 AM
Registered User
 
Join Date: Dec 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
I think You should use User. UserProfile should be custom and can differ on each project. So if you will use same code for another project you can probably fail because of that. Also it is always easy to get user object in code and from that you have no problems to get profile user.get_profile() as you show (and profile is not always needed). So ingeneral I think it will be easier to use other modules and passing them just user object (or id) and not the profile.

What is also could be the solution - write your own class which will be responsible for the users. Just write methods to return profile, return stuff_needed or whatever you want and everything just by passing user object and additional parameters about what you want.

So in short, I'm for using User for Foreign keys, because in my opinion it just more logical, while the User model is always the main one (you always have it) and UserProfile is just extension.





Similar Threads
Thread Thread Starter Forum Replies Last Post
list foreign keys in sql 2000 jomet SQL Server 2000 2 May 1st, 2008 11:15 PM
list foreign keys jomet Oracle 2 March 28th, 2008 04:17 AM
Copying Databases & Foreign Keys donevco Access 5 February 20th, 2007 08:31 AM
inserting records with foreign and primary keys tdaustin Classic ASP Basics 0 October 4th, 2005 12:49 AM
transfering identites as foreign keys santaji SQL Server DTS 1 September 23rd, 2003 09:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.