{"id":360,"date":"2016-03-31T20:19:57","date_gmt":"2016-03-31T11:19:57","guid":{"rendered":"http:\/\/www.onepage.co.kr\/wordpress\/?p=360"},"modified":"2016-03-31T20:40:44","modified_gmt":"2016-03-31T11:40:44","slug":"table-definition","status":"publish","type":"post","link":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/2016\/03\/31\/table-definition\/","title":{"rendered":"Table definition \ud14c\uc774\ube14 \uc815\uc758\uc11c \uc778\ub371\uc2a4 \uc815\uc758\uc11c"},"content":{"rendered":"<p>\ud14c\uc774\ube14\u00a0\uc815\uc758\uc11c\u00a02008 @@<\/p>\n<p>select<br \/>\ncase row_number() over(partition by o.name order by\u00a0 o.name, c.column_id)<br \/>\nwhen 1 then o.name else &#8221; end &#8220;Table Name&#8221;<br \/>\n,c.name &#8220;Column Name&#8221;<br \/>\n,case t.name<br \/>\nwhen &#8216;varchar&#8217; then t.name +'(&#8216;+cast(c.max_length as varchar) +&#8217;)&#8217;<br \/>\nwhen &#8216;char&#8217; then t.name +'(&#8216;+cast(c.max_length as varchar) +&#8217;)&#8217;<br \/>\nwhen &#8216;datetime&#8217; then t.name<br \/>\nelse t.name+'(&#8216;+cast(c.precision as varchar)+&#8217;,&#8217;+cast(c.scale as varchar)+&#8217;)&#8217; end<br \/>\nas &#8220;Column Type&#8221;<br \/>\n,case c.is_nullable when 0 then &#8216;NOT NULL&#8217; else &#8221; end &#8220;Nullable&#8221;<br \/>\n,isnull(d.definition,&#8221;) &#8220;Column Default&#8221;<br \/>\n,case when k.index_id is null then &#8221; else &#8216;YES&#8217; end &#8220;PK&#8221;<br \/>\n,e.value &#8220;Column Comment&#8221;<br \/>\nfrom sys.tables o<br \/>\njoin sys.columns c on(o.object_id = c.object_id and o.type=&#8217;U&#8217;)<br \/>\njoin sys.types t on(c.system_type_id = t.system_type_id and t.schema_id=4)<br \/>\nleft outer join sys.extended_properties e on(c.object_id = e.major_id and c.column_id = e.minor_id)<br \/>\nleft outer join sys.index_columns k on(c.object_id = k.object_id and c.column_id = k.column_id and index_id=1)<br \/>\nleft outer join sys.default_constraints d on(c.object_id=d.parent_object_id and c.column_id=d.parent_column_id and d.type=&#8217;D&#8217;)<br \/>\nwhere o.name &lt;&gt; &#8216;sysdiagrams&#8217;<br \/>\norder by\u00a0 o.name, c.column_id<br \/>\n;<\/p>\n<div class=\"autosourcing-stub-extra\">\n<p><strong>[\ucd9c\ucc98]<\/strong>\u00a0<a href=\"http:\/\/blog.naver.com\/rumo\/90086998671\" target=\"_blank\">[2008] \ud14c\uc774\ube14 \uce7c\ub7fc \uc815\uc758\uc11c \ubf51\ub294 \ucffc\ub9ac<\/a>|<strong>\uc791\uc131\uc790<\/strong>\u00a0<a href=\"http:\/\/blog.naver.com\/rumo\" target=\"_blank\">\uc820\ud2c0\ub9e8<\/a><\/p>\n<\/div>\n<p>\uc778\ub371\uc2a4\u00a0\uc815\uc758\uc11c\u00a02008<\/p>\n<p>SELECT<br \/>\nCASE table_RN WHEN 1 THEN A.table_name ELSE &#8221; END table_name,<br \/>\nCASE RN WHEN 1 THEN A.index_name ELSE &#8221; END index_name,<br \/>\nindex_column_id,<br \/>\ncolum_name,<br \/>\nis_unique,<br \/>\nis_primary_key<br \/>\nFROM<br \/>\n(<\/p>\n<p>select<br \/>\nROW_NUMBER() OVER(ORDER BY o.name, i.is_primary_key desc, i.name, a.index_column_id) sort_RN,<br \/>\nROW_NUMBER() OVER(PARTITION BY o.name ORDER BY o.name, i.is_primary_key desc, i.name, a.index_column_id) table_RN,<br \/>\nROW_NUMBER() OVER(PARTITION BY o.name, i.name ORDER BY o.name, i.is_primary_key desc, i.name, a.index_column_id) RN,<br \/>\no.name table_name,<br \/>\ni.name index_name,<br \/>\nb.name colum_name,<br \/>\na.index_column_id,<br \/>\ncase i.is_unique when 1 then &#8216;YES&#8217; else &#8221; end is_unique,<br \/>\ncase i.is_primary_key when 1 then &#8216;YES&#8217; else &#8221; end is_primary_key,<br \/>\ni.is_primary_key is_primary_key_idx<br \/>\nfrom<br \/>\nsys.all_objects o join<br \/>\nsys.indexes i on(o.object_id=i.object_id) join<br \/>\nsys.index_columns a on(i.object_id=a.object_id and i.index_id = a.index_id)<br \/>\njoin sys.columns b on<br \/>\n(a.object_id = b.object_id and a.column_id = b.column_id)<br \/>\nwhere o.type=&#8217;U&#8217;<br \/>\nand i.index_id &gt; 0<br \/>\nand o.name != &#8216;sysdiagrams&#8217;<br \/>\n)\u00a0A<br \/>\norder by sort_RN<\/p>\n<div class=\"autosourcing-stub-extra\">\n<p><strong>[\ucd9c\ucc98]<\/strong>\u00a0<a href=\"http:\/\/blog.naver.com\/rumo\/90087316410\" target=\"_blank\">[2008] \uc778\ub371\uc2a4\uc815\ubcf4 \ubf51\ub294 \ucffc\ub9ac<\/a>|<strong>\uc791\uc131\uc790<\/strong>\u00a0<a href=\"http:\/\/blog.naver.com\/rumo\" target=\"_blank\">\uc820\ud2c0\ub9e8<\/a><\/p>\n<\/div>\n<p>exerd \ubaa8\ub378\ub9c1<\/p>\n<p><a href=\"http:\/\/blog.naver.com\/PostView.nhn?blogId=rmflt&amp;logNo=110181374443\">http:\/\/blog.naver.com\/PostView.nhn?blogId=rmflt&amp;logNo=110181374443<\/a><\/p>\n<p>\ub370\uc774\ud0c0 \ubaa8\ub378\ub9c1\uc758 \uc774\ud574<\/p>\n<p><a href=\"http:\/\/www.dbguide.net\/db.db?cmd=view&amp;boardUid=148182&amp;boardConfigUid=9&amp;categoryUid=216&amp;boardIdx=132&amp;boardStep=1\">http:\/\/www.dbguide.net\/db.db?cmd=view&amp;boardUid=148182&amp;boardConfigUid=9&amp;categoryUid=216&amp;boardIdx=132&amp;boardStep=1<\/a><\/p>\n<p><b>Download sqljdbc4-2.0.jar<\/b><\/p>\n<p><a href=\"http:\/\/saddev.tistory.com\/18\"><b>[MSSQL]2008 <\/b><b>\ubc31\uc5c5<\/b><b> <\/b><b>\ud30c\uc77c\uc744<\/b><b> 2005<\/b><b>\uc5d0\uc11c<\/b><b> <\/b><b>\ubcf5\uc6d0\ud558\uae30<\/b><\/a><\/p>\n<p><a href=\"http:\/\/saddev.tistory.com\/18\">http:\/\/saddev.tistory.com\/18<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud14c\uc774\ube14\u00a0\uc815\uc758\uc11c\u00a02008 @@ select case row_number() over(partition by o.name order by\u00a0 o.name, c.column_id) when 1 then o.name else &#8221; end &#8220;Table Name&#8221; ,c.name &#8220;Column Name&#8221; ,case t.name when &#8216;varchar&#8217; then t.name +'(&#8216;+cast(c.max_length as varchar) +&#8217;)&#8217; when &#8216;char&#8217; then t.name +'(&#8216;+cast(c.max_length as varchar) +&#8217;)&#8217; when &#8216;datetime&#8217; then t.name else t.name+'(&#8216;+cast(c.precision as varchar)+&#8217;,&#8217;+cast(c.scale as varchar)+&#8217;)&#8217; end as &#8220;Column [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-360","post","type-post","status-publish","format-standard","hentry","category-mssql"],"_links":{"self":[{"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/360","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=360"}],"version-history":[{"count":4,"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/360\/revisions"}],"predecessor-version":[{"id":378,"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/360\/revisions\/378"}],"wp:attachment":[{"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.onepage.co.kr\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}