{"id":114,"date":"2006-07-30T09:34:39","date_gmt":"2006-07-30T07:34:39","guid":{"rendered":"http:\/\/www.glorf.it\/blog\/2006\/07\/30\/sql-talk\/primarschlussel-felder-aus-information_schema-tabellen-ermitteln\/"},"modified":"2006-07-30T09:34:39","modified_gmt":"2006-07-30T07:34:39","slug":"primarschlussel-felder-aus-information_schema-tabellen-ermitteln","status":"publish","type":"post","link":"http:\/\/www.glorf.it\/blog\/2006\/07\/30\/sql-talk\/primarschlussel-felder-aus-information_schema-tabellen-ermitteln","title":{"rendered":"Prim&#228;rschl&#252;ssel-Felder aus INFORMATION_SCHEMA-Tabellen ermitteln"},"content":{"rendered":"<p>Gestern fragte jemand in der Newsgroup <a href=\"news:microsoft.public.de.sqlserver\">microsoft.public.de.sqlserver<\/a> wie man die Prim&#228;rschl&#252;ssel-Felder aus INFORMATION_SCHEMA-Tabellen ermitteln kann.<br \/>\nSo geht:<\/p>\n<p><code lang=\"SQL\">select CU.COLUMN_NAME<br \/>\n\tfrom INFORMATION_SCHEMA.KEY_COLUMN_USAGE  as CU<br \/>\n\tjoin INFORMATION_SCHEMA.TABLE_CONSTRAINTS as TC<br \/>\n\t  on CU.CONSTRAINT_CATALOG=TC.CONSTRAINT_CATALOG<br \/>\n\t and CU.CONSTRAINT_SCHEMA=TC.CONSTRAINT_SCHEMA<br \/>\n\t and CU.CONSTRAINT_NAME=TC.CONSTRAINT_NAME<br \/>\n\twhere CONSTRAINT_TYPE = N&#x0027;PRIMARY KEY&#x0027;<br \/>\n\t  and TC.TABLE_CATALOG = N&#x0027;AdventureWorks&#x0027;<br \/>\n\t  and TC.TABLE_SCHEMA = N&#x0027;Person&#x0027;<br \/>\n\t  and TC.TABLE_NAME = N&#x0027;MyAddress&#x0027;<br \/>\n\torder by ORDINAL_POSITION asc <\/code><\/p>\n<p>Damit bekommt man eine Liste der Felder in der richtigen Reihenfolge. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gestern fragte jemand in der Newsgroup microsoft.public.de.sqlserver wie man die Prim&#228;rschl&#252;ssel-Felder aus INFORMATION_SCHEMA-Tabellen ermitteln kann. So geht: select CU.COLUMN_NAME from INFORMATION_SCHEMA.KEY_COLUMN_USAGE as CU join INFORMATION_SCHEMA.TABLE_CONSTRAINTS as TC on CU.CONSTRAINT_CATALOG=TC.CONSTRAINT_CATALOG and CU.CONSTRAINT_SCHEMA=TC.CONSTRAINT_SCHEMA and CU.CONSTRAINT_NAME=TC.CONSTRAINT_NAME where CONSTRAINT_TYPE = N&#x0027;PRIMARY KEY&#x0027; and TC.TABLE_CATALOG = N&#x0027;AdventureWorks&#x0027; and TC.TABLE_SCHEMA = N&#x0027;Person&#x0027; and TC.TABLE_NAME = N&#x0027;MyAddress&#x0027; order by ORDINAL_POSITION asc Damit [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts\/114"}],"collection":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":0,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/posts\/114\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/media?parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/categories?post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.glorf.it\/blog\/wp-json\/wp\/v2\/tags?post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}