Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

All columns along with flag for foreign key or not Expand / Collapse
Author
Message
Posted Thursday, March 5, 2009 11:48 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 28, 2013 5:28 AM
Points: 42, Visits: 137
Hi

I need list of all columns in the database along with a flag or what ever which should indicate whether it is a key(foreign key) or not. Can any one please help on this


/********************************************************
Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
********************************************************/
Post #669961
Posted Friday, March 6, 2009 1:30 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, April 22, 2014 6:56 AM
Points: 1,330, Visits: 1,434
Hello,

You could probably build a formatted report using this code snippet as the starting point:-

Select
*
From
sys.columns SC
Left Join sys.foreign_key_columns FKC
On (FKC.parent_object_id = SC.object_id) And (FKC.parent_column_id = SC.column_id)

Regards,

John Marsh


www.sql.lu
SQL Server Luxembourg User Group
Post #669994
Posted Saturday, March 7, 2009 9:53 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Friday, June 28, 2013 5:28 AM
Points: 42, Visits: 137
Thanq john actually i am sarching for any buit in function or view for this any ways thnq for the reply

/********************************************************
Technology is just a tool,in terms of getting the kids working together and motivating them,the teacher is the most important.
********************************************************/
Post #671059
Posted Sunday, March 8, 2009 1:58 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 1:43 PM
Points: 40,411, Visits: 36,861
grngarlapati (3/7/2009)
Thanq john actually i am sarching for any buit in function or view for this any ways thnq for the reply


The views that John used in his query are built-in system views. There's no view of function that, by itself, will give you what you want, you'll have to build a query up using sys.columns and sys.foreign_key_columns.



Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #671079
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse