• Mike C (5/21/2007)


    <FONT color=#111111>Actually the question is <EM>"How can you get the <STRONG>number </STRONG>of columns involved in any constraint of any table in SQL Server 2005?"</EM> None of the answers returns an actual number. But two of the queries provided </FONT><FONT color=#111111>return the one row for each column, so you can manually count them up and determine the number of columns involved:</FONT>

    <FONT color=#111111><FONT color=#1111dd><EM>Select <STRONG>column_name</STRONG> From INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_name = <TABLENAME>and constraint_name = <PRIMAYKEYCONSTRAINTNAME>

    </EM><EM>Select <STRONG>constraint_name</STRONG> From INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_name = <TABLENAME>and constraint_name =</EM></FONT> </FONT>

    <FONT color=#111111>This "correct" answer <EM>(<FONT color=#1111ff>Select <STRONG>column_name</STRONG> From INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_name = <TABLENAME>and constraint_name =</FONT><FONT color=#00008b> ) </FONT></EM>is only "more correct" than the other answerif you wantto get the <STRONG><EM>Names</EM></STRONG> of all columns involved in a constraint of a table, not the <STRONG><EM>Number</EM></STRONG>.</FONT>

    +1