Solved

I also wanted to display the Tablecolumn name ?????? do not know how?

Posted on 2011-03-21
3
432 Views
Last Modified: 2012-05-11
SELECT  OBJECT_NAME(parent_object_id) AS DefinedInTable ,
        OBJECT_NAME(referenced_object_id) AS ReferenceTable ,
        OBJECT_NAME(????????) AS Tablecolumn ,
        name AS ForeignKeyName
FROM    sys.foreign_keys
WHERE   OBJECT_NAME(parent_object_id) = 'AceData' ;
0
Comment
Question by:goodk
3 Comments
 
LVL 10

Assisted Solution

by:khan_webguru
khan_webguru earned 50 total points
ID: 35182147
Hello Bro!

You can do this by any of following quires

 
SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name = 'THE_COLUMN_NAME' )

Open in new window


Or

 
SELECT name FROM sysobjects WHERE id IN ( SELECT id FROM syscolumns WHERE name like '%PART_OF_NAME%' )

Open in new window


Or

 
SELECT  o.name, o.type_desc, p.name, t.name, p.max_length, p.precision, p.scale, 
        p.is_output, p.is_cursor_ref, p.has_default_value, p.is_xml_document, p.default_value
FROM    sys.all_objects o
        inner join sys.all_parameters p on o.object_id = p.object_id
        inner join sys.types t on p.user_type_id = t.user_type_id
order by o.type_desc, o.name, p.name

Open in new window


Or

 
SELECT column_name 'Column Name',
data_type 'Data Type'
FROM information_schema.columns
WHERE table_name = 'Address'

Open in new window



Or

 
select column_name, data_type, character_maximum_length from information_schema.columns
where table_name = 'myTable'

Open in new window



Or

 
EXEC sp_columns @table_name

LIKE

EXEC sp_columns "Employee"

Open in new window


I hope this will solve your problem

Regards,

Asif Ahmed Khan
0
 
LVL 3

Accepted Solution

by:
ssisworo earned 450 total points
ID: 35182330
Have you tried this :

SELECT  OBJECT_NAME(foreign_keys.parent_object_id) AS DefinedInTable ,
        OBJECT_NAME(foreign_keys.referenced_object_id) AS ReferenceTable ,
        COL_NAME(foreign_keys.referenced_object_id,foreign_key_columns.referenced_column_id ) AS ReferenceTablecolumn,
        COL_NAME(foreign_keys.parent_object_id,foreign_key_columns.parent_column_id ) AS DefinedTablecolumn,
        name AS ForeignKeyName
FROM    sys.foreign_keys, sys.foreign_key_columns
WHERE   OBJECT_NAME(foreign_keys.parent_object_id) = 'AceData' and
        foreign_keys.OBJECT_ID = foreign_key_columns.constraint_object_id;
0
 

Author Closing Comment

by:goodk
ID: 35185198
thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now