﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2008 / SQL Server 2008 - General  / How to get schemaname, tablename, identity column, foreign key constraints / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Thu, 23 May 2013 02:25:00 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>Hello!Something like this:[code="sql"]SELECT CTU.TABLE_SCHEMA + '.' + CTU.TABLE_NAME [TABLE],KCU.COLUMN_NAME [COLUMN],CTU2.TABLE_SCHEMA + '.' + CTU2.TABLE_NAME [REFERENCED_TABLE],KCU2.COLUMN_NAME [REFERENCED_COLUMN],CTU.CONSTRAINT_NAME [FK_CONSTRAINT]FROM INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE CTU JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU ON KCU.CONSTRAINT_NAME = CTU.CONSTRAINT_NAME AND KCU.CONSTRAINT_SCHEMA = CTU.CONSTRAINT_SCHEMA JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS RC ON RC.CONSTRAINT_NAME = CTU.CONSTRAINT_NAME AND RC.CONSTRAINT_SCHEMA = CTU.CONSTRAINT_SCHEMA JOIN INFORMATION_SCHEMA.CONSTRAINT_TABLE_USAGE CTU2 ON CTU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME AND CTU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU2 ON KCU2.CONSTRAINT_NAME = RC.UNIQUE_CONSTRAINT_NAME AND KCU2.CONSTRAINT_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMAWHERE CTU.TABLE_NAME = 'tablename'AND CTU.CONSTRAINT_NAME LIKE 'FK_%'[/code]Lacc</description><pubDate>Thu, 09 Sep 2010 02:26:26 GMT</pubDate><dc:creator>Lacc</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>Okay how about taking this one step further, and show the column names that are in the Foreign Key?  Is there a way?  Each time I attempt that I end up with errors.</description><pubDate>Fri, 04 Jun 2010 11:11:42 GMT</pubDate><dc:creator>lucasm-630215</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>Thanks ALL. Thanks lot.</description><pubDate>Thu, 20 May 2010 07:01:20 GMT</pubDate><dc:creator>nithiyanandam-447806</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>It really depends on your needs. That query is returning the data you outlined.</description><pubDate>Thu, 20 May 2010 06:23:44 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>[quote][b]Nagesh S-432384 (5/20/2010)[/b][hr]Query is looking good.Nag[/quote]you just miss spelled the table_name as tabnle_name :-) nothing else is the problem.Nag</description><pubDate>Thu, 20 May 2010 06:14:13 GMT</pubDate><dc:creator>Nagesh S-432384</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>Query is looking good.Nag</description><pubDate>Thu, 20 May 2010 06:11:38 GMT</pubDate><dc:creator>Nagesh S-432384</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>I tried to get the above qry. could you please check and verify this query...select s.name schemaname, o.name tablename, i.name identitycolname,         ins.constraint_name constraintnamefrom sys.schemas sjoin sys.sysobjects o on o.uid = s.schema_idleft join sys.identity_columns i on o.id = i.object_idleft join information_schema.constraint_table_usage ins on                ins.tabnle_name = o.name         and ins.constraint_name in ( select insc.constraint_name from                      information_schema.referential_constraints insc )where o.xtype = 'U'order by s.name, o.nameThanks in advance..Nithiyanandam.S</description><pubDate>Thu, 20 May 2010 00:59:25 GMT</pubDate><dc:creator>nithiyanandam-447806</dc:creator></item><item><title>RE: How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>Dynamic methods are frequently problematic, but to get the data you're looking for, check out the system views available under the schema called INFORMATION_SCHEMA. They should supply you with everything you need.</description><pubDate>Wed, 19 May 2010 08:19:14 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>How to get schemaname, tablename, identity column, foreign key constraints</title><link>http://www.sqlservercentral.com/Forums/Topic924278-391-1.aspx</link><description>Hi,i need to create a select query to get schemaname, tablename, identity column, foreign key constraints for whole database. for using dynamic query to use bulk import i need to get these informations.</description><pubDate>Wed, 19 May 2010 07:18:36 GMT</pubDate><dc:creator>nithiyanandam-447806</dc:creator></item></channel></rss>